[R] How to adjust the start of a series to zero? (i.e. subtract the first value from the sequence)
dwinsemius at comcast.net
Mon Jul 2 21:25:43 CEST 2012
On Jul 2, 2012, at 2:21 AM, Bert Gunter wrote:
> 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-
> 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
That's interesting to me. I almost never use `within`. I'm wondering
if I'm missing something? As I read the help page `within` is going to
do something different when the expression is an assignment, so one
could do the following with `within`
within(dfrm, var2 <- var2/100)
... but that would have no lasting effect since its result was not
assigned, so I do not se an advantage over:
dfrm$var2 <- with(dfrm, var2/100)
In both case one would still need to assign the result to an object,
in the case of the first to 'dfrm' itself and in the second case to
None of the examples on the help page use `within`. Is that because it
is inferior to transform?
> -- Bert
> On Sun, Jul 1, 2012 at 6:39 PM, Kristiina Hurme
> <kristiina.hurme at 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,
>> point time mean sd adj_mean.point adj_mean.time
>> 1 1 1 52.50100 1.5073927 1 1
>> 3 1 2 54.50182 0.8510329 1 2
>> 4 1 3 56.60174 1.5787222 1 3
>> 5 1 4 57.20000 1.2292726 1 4
>> 6 1 5 59.30000 2.2632327 1 5
>> 7 1 6 57.80089 1.4745218 1 6
>> but am getting the columns in duplicate, rather than it performing
>> function. Any advice?
>> Thanks again,
>> View this message in context:
>> Sent from the R help mailing list archive at Nabble.com.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> Bert Gunter
> Genentech Nonclinical Biostatistics
> Internal Contact Info:
> Phone: 467-7374
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help