r

Is it possible to break axis labels into 2 lines in base graphics?

I am trying to have the x-axis labels to be split into two lines. I would also like the labels to be rotated 45 degrees. How can I do this? What I have so far: N <- 10 dnow <- data.frame(x=1:N, y=runif(N), labels=paste("This is observation ",1:N)) with(dnow, plot(x,y, xaxt="n", xlab="")) atn <- seq(1,N,3) axis(1, at=atn, labels=labels[...

Returning a vector of attributes shared by a set of objects

I have a list of lm (linear model) objects. How can I select a particular element (such as the intercept, rank, or residuals) from all the objects in a single call? ...

How to get R to recognize your working directory as its working directory?

I use R under Windows on several machines. I know you can set the working directory from within an R script, like this setwd("C:/Documents and Settings/username/My Documents/x/y/z") ... but then this breaks the portability of the script. It's also annoying to have to reverse all the slashes (since Windows gives you backslashes) Is th...

How to make R use all processors?

I have a quad-core laptop running Windows XP, but looking at Task Manager R only ever seems to use one processor at a time. How can I make R use all four processors and speed up my R programs? ...

Fonts in R plots

What graphics devices let me use system fonts for text within charts? The base graphics system only has a small amount of documentation around the par(family=...) options. Ideally I'd like to be able to use any font I can browse through a tool like xfontsel on Linux or the equivalent utilities on other platforms. My current solution is...

Getting value rather than formula in RGoogleDocs

Is there an easy way to read the value of the cells rather than the formula? By the way I only get this problem in a spreadsheet that I have published but not in spreadsheets that are private. So for instance in a cell whose value was created by simply using the value from the cell immediately to the left in the Google spreadsheet I woul...

How to print R graphics to multiple pages of a PDF and multiple PDFs?

I know that pdf("myOut.pdf") will print to a PDF in R. What if I want to Make a loop that prints subsequent graphs on new pages of a PDF file (appending to the end)? Make a loop that prints subsequent graphs to new PDF files (one graph per file)? ...

POSIXct times around DST?

I want to subtract 1 day from a POSIX date and end up at the same time around DST. For example, when I add a day: > as.POSIXct('2009-03-08 23:00:00.000') + 86400 [1] "2009-03-09 23:00:00 EDT" But when I go past, it offsets: > as.POSIXct('2009-03-08 23:00:00.000') - 86400 [1] "2009-03-07 22:00:00 EST" What's the best way to deal ...

Reading binary data of indeterminate length in R

I would like to read a binary file -- of indeterminate length -- directly from a URL in R. Using readBin to read from a URL, without specifying the file size, does not work. anImage <- readBin('http://user2010.org/pics/useR-large.png','raw') Is there another approach that would allow this? ...

Aspect oriented programming in r: Any libraries available?

Are there any R-project packages that implement AOP? Or even better an example of an R package that uses any such AOP library. ...

Scraping html tables into R data frames using the XML package

How do I scrape html tables using the XML package? Take, for example, this wikipedia page on the Brazilian soccer team. I would like to read it in R and get the "list of all matches Brazil have played against FIFA recognised teams" table as a data.frame. How can I do this? ...

R: How do I set what plot() labels the x-axis with?

I have a plot() that I'm trying to make, but I do not want the x-values to be used as the axis labels...I want a different character vector that I want to use as labels, in the standard way: Use as many as will fit, drop the others, etc. What should I pass to plot() to make this happen? For example, consider d <- data.frame(x=1:5,y=10:...

Debugging lapply/sapply calls

Code written using lapply and friends is usually easier on the eyes and more Rish than loops. I love lapply just as much as the next guy, but how do I debug it when things go wrong? For example: > ## a list composed of numeric elements > x <- as.list(-2:2) > ## turn one of the elements into characters > x[[2]] <- "what?!?" > > ## usi...

Questions about coloring in ggplot2

In ggplot2, how could I change the color of coloring in scatter plot? ...

Asynchronous network IO using r: Any existing packages

Are there any R-project packages that facilitate asynchronous network IO? I'm think here along the lines of Ruby's Eventmachine or Python's Twisted. If there are several such packages/libraries which is the best in terms of: - performance - features ...

R web application introduction

I doubt this is the right place to ask the question, but I was wondering if there is a good place for an introduction to developing web apps in R. I know people are doing it and I know about where to find out about RApache and brew but any kind of walkthrough? Just checking before I start on my own. ...

plotting points on top of image in R

These days I am extensively using R to scatter plots. Most of the plotting is concerned with image processing, Recently I was thinking of plotting the scatter plots over an image. For example, I want something like this, The background needs to be filled with my image. With a particular scale. And I should be able to draw points (co-or...

Changing annotations in time series plots in R

While I can change annotations with the generic plot command turning off axes and annotations and specifying them again using the axis command e.g. cars <- c(1, 3, 6, 4, 9) plot(cars, type="o", col="blue", ylim=range(0, cars), axes=FALSE, ann=FALSE) axis(1, at=1:5, lab=c("Mon","Tue","Wed","Thu","Fri")) I cant do it with time series o...

More than 9 backreferences in gsub()

How to use gsub with more than 9 backreferences? I would expect the output in the example below to be "e, g, i, j, o". > test <- "abcdefghijklmnop" > gsub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)", "\\5, \\7, \\9, \\10, \\15", test, perl = TRUE) [1] "e, g, i, a0, a5" ...

On the issue of automatic time series fitting using R

we have to fit about 2000 or odd time series every month, they have very idiosyncratic behavior in particular, some are arma/arima, some are ewma, some are arch/garch with or without seasonality and/or trend (only thing in common is the time series aspect). one can in theory build ensemble model with aic or bic criterion to choose the b...