[R] How can I map "by" results to original list of indices or first difference of column of data.frame with two factors?
jholtman at gmail.com
Sun Mar 4 02:55:45 CET 2012
If you would post a subset of your data so that we can see what you
are talking about, we could probably help you come up with a solution.
On Sat, Mar 3, 2012 at 7:50 PM, Mikhail Titov <mlt at gmx.us> wrote:
> 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?
> 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.
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
More information about the R-help