Hello!

I’m having stacked data in a data.frame with 2 factors, ordered POSIXct, and 
actual value as numeric (as if for lattice::xyplot).

I would like to calculate first difference using “diff” function within 
corresponding subsets/partitions. Since data.frame is organized by factors and 
has sorted dates, it seems like "by" is a good candidate for the job. However 
it returns just a dumb list of vectors.

It seems that I can use either expand.grid to remap results of "by" and hope 
that I won't mess up order, or I can use "unique(subset(x,select=c(foo,bar)))"

In overall it looks like quite many steps for such task not counting assignment 
of those differences back to original data.frame starting from 2nd position in 
each partition (as diff returns shorter vector).

Am I on the right track or is there an easier way to do that?

Mikhail

______________________________________________
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.

Reply via email to