[R] How to adjust the start of a series to zero? (i.e. subtract the first value from the sequence)

Kristiina Hurme kristiina.hurme at uconn.edu
Mon Jul 2 03:39:32 CEST 2012


Thanks everyone. 
I tried them all, and got all to work except for the last one. 

I tried
> sort2v4$adj_mean<-within(sort2v4, ave(mean, point, FUN=function(x)x-x[1]))
> head(sort2v4)
  point time     mean        sd adj_mean.point adj_mean.time adj_mean.mean
adj_mean.sd
1     1    1 52.50100 1.5073927              1             1      52.50100  
1.5073927
3     1    2 54.50182 0.8510329              1             2      54.50182  
0.8510329
4     1    3 56.60174 1.5787222              1             3      56.60174  
1.5787222
5     1    4 57.20000 1.2292726              1             4      57.20000  
1.2292726
6     1    5 59.30000 2.2632327              1             5      59.30000  
2.2632327
7     1    6 57.80089 1.4745218              1             6      57.80089  
1.4745218

but am getting the columns in duplicate, rather than it performing the
function. Any advice?

Thanks again, 
Kristiina

--
View this message in context: http://r.789695.n4.nabble.com/How-to-adjust-the-start-of-a-series-to-zero-i-e-subtract-the-first-value-from-the-sequence-tp4634999p4635062.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list