[R] regression on data subsets in datafile

marcel marcelcurlin at gmail.com
Mon Sep 12 09:42:35 CEST 2011

I have data of the form

tC <- textConnection("
Subject	Date	parameter1
bob	3/2/99	10
bob	4/2/99	10
bob	5/5/99	10
bob	6/27/99	NA
bob	8/35/01	10
bob	3/2/02	10
steve	1/2/99	4
steve	2/2/00	7
steve	3/2/01	10
steve	4/2/02	NA
steve	5/2/03	16
kevin	6/5/04	24
data <- read.table(header=TRUE, tC)

I am trying to calculate rate of change of parameter1 in units/day for each
person. I think I need something like:
"lapply(split(mydata, mydata$ppt), function(x) lm(parameter1 ~ day,

I am not sure how to handle the dates in order to have the first day for
each person be time = 0, and the remaining dates to be handled as days since
time 0. Also, is there a way to add the resulting slopes to the data set as
a new column? 


View this message in context: http://r.789695.n4.nabble.com/regression-on-data-subsets-in-datafile-tp3806743p3806743.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list