[R] transforming data based on factors in a dataframe

Carly Huitema carly.huitema at gmail.com
Wed Apr 25 16:57:48 CEST 2012


Hello R-help list,

I would really appreciate help with my factoring problem.

My generated data is this:

df <- expand.grid(T=seq(10,80, by=5), conc=rep(c(1, 3, 7), 2))
df$curve <- as.factor(rep(1:6, each=length(seq(10,80, by=5))))
df$counts <- 3*df$T/df$conc + rnorm(df$T,0,2)

plot(counts~T, df)


What I would like to do add a new column to the dataframe of zeroed
data (say df$counts.zeroed). For each curve (designated by factor
df$curve) I want to take the value in counts and subtract the minimum
value for that curve. However, I don't really have an idea of how to
approach this problem and haven't found anything in my searches.

And just as a second question, my second line of code assigns the
factors, but if there is a nicer way of doing this I would really
appreciate knowing how.

Thanks for any help!
Carly



More information about the R-help mailing list