Hi Kristina:

That's because I gave you the wrong function. It should be "with" not
"within", as:

sort2v4$adj_mean<-with(sort2v4, ave(mean, point, FUN=function(x)x-x[1]))

within(dat,...) returns dat suitably modified.
with (dat,...) just returns the result of the function.

I frequently use within() when I mean with(), unfortunately.  Sorry for the
error.

-- Bert

On Sun, Jul 1, 2012 at 6:39 PM, Kristiina Hurme
<kristiina.hurme@uconn.edu>wrote:

> 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.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

	[[alternative HTML version deleted]]

