r

Fitting polynomial model to data in R

I've read the answers to this question and they are quite helpful, but I need help particularly in R. I have an example data set in R as follows: x <- c(32,64,96,118,126,144,152.5,158) y <- c(99.5,104.8,108.5,100,86,64,35.3,15) I want to fit a model to these data so that y = f(x). I want it to be a 3rd order polynomial model. How...

How to convert a matrix to a 1 dimensional array in R

Hi I have a matrix file that is 32X48 and I want to put all of the values into a single dimensional array in R. Right now I am only able to get the last row of data. trgtFN_intensity <- "1074_B09_1- 4_5mM_Xgal_7d_W.cropped.resized.grey.png.red.median.colony.txt"; read.table(trgtFN_intensity, sep="\t") -> tmp_int maxrow_int <- nrow(...

Use aggregate with a function that uses data from two columns (e.g. cov or prod)

I have a long time series of daily data and 101 columns. Each month I would like to calculate the cov of each of the first 100 columns with the 101st column. This would generate a monthly covariance with the 101st column for each of the 100 columns based on daily data. It seems that aggregate does what I want with functions that take a s...

R: Simplify this. Ave or Aggregate with several inputs

How can I write this all in one line? mydata is a zoo series, limit is a numeric vector of the same size tmp <- ave(coredata(mydata),as.Date(index(mydata)),FUN = function(x) ( (cummax(x)-x )) ) tmp <- (tmp < limit) final <- ave(tmp,as.Date(index(mydata)),FUN = function(x) cumprod( x) ) I've tried to use two vectors as argument to ave...

ggplot2: Use options for multiple plots

I would like to create 10 plots that have different data, but the same optical appearance. As an example, I’d like to change the colour of the gridline for each plot. This could be done by adding + opts(panel.grid.major = theme_line(colour = "white") to each plot definition. However, when I now decide to change background colour to l...

Set default port number in HTML help

Well, the title is quite self-explanatory... Is it possible to set default port number for R's HTML help? Each time I start HTML help, port number gets changed. ...

Boxplot in R showing the mean (again)

I saw http://stackoverflow.com/questions/2492947/boxplot-in-r-showing-the-mean I'm interested in the ggplot solution. But what I am plotting are averages already so I don't want to do an average of an average. I do have the true mean stored in TrueAvgCPC. Here is what I tried, but it's not working: p <- qplot(Mydf$Network,Mydf$Avg.CPC...

ggplot2 plotmatrix - changing text labels

I'm using the plotmatrix function in ggplot2 (ggplot2_0.8.8) and would like to override the column names displayed from my dataframe, e.g. plotmatrix(mtcars) + opts(strip.text.x = theme_text(size=20)) I can alter the properties of strip.text.x and strip.text.y with opts, but where can I change the text itself e.g. I would like "mpg" r...

write.table(...,append=T) : Cannot open the connection

I'm wondering if anyone else has ever encountered this problem. I'm writing a fairly small amount of data to a csv file. It's about 30 lines, 50 times. I'm using a for loop to write data to the file. It seems "finicky" sometimes the operation completes successfully, and other times it stops after the first ten times (300 lines) other...

How to remove double quotes around NULL values in write.csv?

I am working on exporting a data.frame to a csv for use in an ecommerce system after I have done some analysis on it. I am removing the NA values before the extract as they are not allowed in the system I am adding the data to. The process I have looks like this, my data.frame is called prod_out: prod_out[is.na(prod_out)] <- c("") pr...

ggplot2: Changing the layout of the legend

Right now, the legend by default looks something like this: Legend Title x-1 y-2 z-3 But is it possible to make it look something like this? Legend Title x-1 y-2 z-3 ...

reshape: cast oddity

Either it's late, or I've found a bug, or cast doesn't like colnames with "." in them. This all happens inside a function, but it "doesn't work" outside of a function as much as it doesn't work inside of it. x <- structure(list(df.q6 = structure(c(1L, 1L, 1L, 11L, 11L, 9L, 4L, 11L, 1L, 1L, 2L, 2L, 11L, 5L, 4L, 9L, 4L, 4L, 1L, 9L, 4L, ...

Read xts from CSV file in R

Hi, I'm trying to read time series from CSV file and save them as xts to be able to process them with quantmod. The problem is that numeric values are not parsed. CSV file: name;amount;datetime test1;3;2010-09-23 19:00:00.057 test2;9;2010-09-23 19:00:00.073 R code: library(xts) ColClasses = c("character", "numeric", "character") Da...

Color schemes in R?

Does R have color palettes? In other words, I am looking for an array of 6 or so color names that go well together in a graph or plot; maybe there are some predefined schemes like that? ...

Pivoting rows into columns

Suppose (to simplify) I have a table containing some control vs. treatment data: Which, Color, Response, Count Control, Red, 2, 10 Control, Blue, 3, 20 Treatment, Red, 1, 14 Treatment, Blue, 4, 21 For each color, I want a single row with the control and treatment data, i.e.: Color, Response.Control, Count.Control, Response.Treatment,...

R: Turning RData file into script files

Is there a straightforward way to turn the functions of a .RData file into a normal code file (.R)? ...

how to prevent the output of R to scroll away in bash?

Possible Duplicate: Equivalent to unix less command within R console I am using R under unix in bash. Sometimes the output of a command has more lines than the bash. How do I prevent the output from scrolling away? I.e. is there some equivalent of less and less -S in R? ...

Add comma to numbers every three digits in R

Hey guys, is there a function in R to display large numbers separated with commas? from: 1000000 to: 1,000,000 ...

Auto-completion for Stat ET / Eclipse?

Dear all, after using sciviews-K for a while, I am about to give the R Eclipse combo another chanced. I updated to Helios on my Mac OS X Snow Leopard. So far everything that used to make trouble with Eclipse works, but somehow I miss the auto-completion of code. Or at least the standard suggestion of paramaters when you use R functions...

Returning a logical vector for matches: regexp supported?

I want to return a logical vector for regexp matches over a character vector, but match or %in do not seem to support regular expressions, e.g.: > x <- c("Bill", "Brett", "Jane") > grep("^B", x) [1] 1 2 > x %in% "^B" [1] FALSE FALSE FALSE I would like this to return [1] TRUE TRUE FALSE Ideas? Thanks, Roberto ...