r

R zoo series sliding window calculation

Given I have a zoo dataset, I'd like to perform a sliding operation against it with the result being another zoo dataset. > x Y (09/24/09 08:00:13) 3.1 (09/24/09 08:05:13) 4.2 (09/24/09 08:10:13) 4.5 (09/24/09 08:15:13) 9.4 (09/24/09 08:20:13) 9.8 (09/24/09 08:25:13) 7.7 (09/24/09 08:30:13) 13.3 (09/2...

How can I learn to create beautiful infographics (with connection to my R knowledge)?

Hello all. I am a devoted R (r-project.org) user, and love infographics. I just came across this article: http://www.noupe.com/design/fantastic-information-architecture-resources.html Giving a long list of resources for information designers. And it raised in me the desire to do more beautiful (not just informative) R plots. Do you have...

Use Windows (TTF) font in R graphics

Is it possible to use a TTF font in R? Is the cairo package intended for this task? How would a minimal example look like? ...

R: calling a function from a namespace

I'm trying to alter the functionality of a few commands in a package in R. It's easy enough to see the source of the commands. However the function calls other functions that are in the package namespace. These functions are not exported objects. So how can I access them? specific example: How would I access the asCall() function that i...

Installing all CRAN packages that are not already installed?

The following R commands will install all CRAN packages: availablePackages <- available.packages()[,1] install.packages(availablePackages) And the following command will list all installed packages: installedPackages <- .packages(all.available = TRUE) My question is: How do I instruct R to install all CRAN packages that are not alr...

R: apt-get install r-cran-foo vs. install.packages("foo")

When installing R packages (say mcmcpack in this example) under Ubuntu I have the choice between the following two methods of installation: # Let the distribution's packaging system take care of installation/upgrades apt-get install r-cran-mcmcpack # Let R take care of installation/upgrades install.packages("mcmcpack") Questions: I...

Inspect S4 methods

How can I view the definition of a S4 function? For instance, I would like to see the definition of TSconnect in package TSdbi. The command showMethods("TSconnect") reveals that there is, among others, a function for drv="histQuoteDriver", dbname="character". How can I see the definition of this function? If it were a S3 function, th...

alternative to "!is.null()" in R

Hello, my R code ends up containing plethora of statements of the form: if (!is.null(aVariable)) { do whatever } But this kind of statement is hard to read because it contains two negations. I would prefer something like: if (is.defined(aVariable)) { do whatever } Does a is.defined type function that does the oppo...

R from within Java

What's the best way to call R functionality from within Java? I'm looking for a quick, easy and reliable way to make standard 2d scatter plots and histograms in R using my Java applications. I was wondering which packages/interfaces that came up in a quick Google search would be most convenient to use. I look forward to your suggesti...

How to use an image as a point in ggplot?

Is there some way to use a specific small image as a point in a scatterplot with ggplot2. Ideally I will want to resize the images based on an variable. Here's an example: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) p + geom_point(aes(size = qsec, shape = factor(cyl))) So I basically want to know if there is a way to supply a...

How to use a variable name in a mySQL statement?

I'm using R to call a mySQL statement, where I define the variable outside the statement e.g. foo = 23; dbGetQuery(con, "select surname from names WHERE age = '.foo.' ;") But this returns an empty set, I've googled around and tried'.&foo.' ".foo." '".&&foo."' and many different combinations, but none of them work, I think this s...

Display only one line for each NA Value

At some point in my script I like to see the number of missing values in my data.frame and display them. In my case I have: out <- read.csv(file="...../OUT.csv", na.strings="NULL") sum(is.na(out$codeHelper)) out[is.na(out$codeHelper),c(1,length(colnames(out)))] It works perfectly fine. However, the last command obviously gives me th...

Reshaping data.frame from wide to long format

I have some trouble to convert my data.frame from a wide table to a long table. At the moment it looks like this: Code Country 1950 1951 1952 1953 1954 AFG Afghanistan 20,249 21,352 22,532 23,557 24,555 ALB Albania 8,097 8,986 10,058 11,123 12,246 Now I like to transform this data.frame into a ...

What R packages are available for binary data that is both correlated and clustered?

I'm working on a project now that's rather unlike anything I've done before. I have two tests with binary results that will be administered to the same sample, which is drawn from a clustered population (i.e., some subjects will be from the same family). I'd like to compare proportions of positive test results, but the clustering makes...

Bind variables in R DBI

In R's DBI package, I'm not finding a facility for using bound variables. I did find a document (the original vignette from 2002) that says about bound variables, "Perhaps the DBI could at some point in the future implement this feature", but it looks like so far that's left undone. What do people in R use for a substitute? Just conca...

How do I use plyr to number rows?

Basically I want an autoincremented id column based on my cohorts - in this case .(kmer, cvCut) > myDataFrame size kmer cvCut cumsum 1 8132 23 10 8132 10000 778 23 10 13789274 30000 324 23 10 23658740 50000 182 23 10 28534840 100000 65 23 10 33943283 200000 25 23 10 37954383 ...

How can I estimate the logarithmic form of data points using R?

I have data points that represent a logarithmic function. Is there an approach where I can just estimate the function that describes this data using R? Thanks. ...

How can I show an ASCII character in R

I want to show a block ascii character in R █ (its ascii code is 219) How can I show it in terminal? I am using RGui on WinXP ...

Plot multiple functions in R

I previously asked this question which was useful in plotting a function. I want to try and plot twenty functions on the same axes to illustrate how a function varies between two ranges. I have successfully done this using individually specified functions, but I wanted to do this using a loop. What I have attempted doing is: ## add gg...

Getting "raw" data from frequency table

Hi there, I've been looking around for some data about naming trends in USA. I managed to get top 1000 names for babies born in 2008. The data is formated in this manor: male.name n.male female.name n.female Jacob 22272 Emma 18587 Michael 20298 Isabella 18377 Ethan 20004 Emily 17217 Joshua 18924 Madison 16853 Daniel 18717 Ava 168...