Thanks Gabor,
The method works perfectly for my needs!
Phil,
Thanks for the tip about set.seed() and for the code. I really like the
simplicity of using mapply, and your example is very close to accomplishing
what I was looking for, but it breaks down under one type of situation. In
part
And here is a pure R solution:
> m <- merge(df1, df2, by = "category")
> m$datediff <- m$date.x - m$date.y
> m <- m[order(m$category, m$date.x, m$date.y), ]
> m
category A.x date.x A.y date.y datediff
2 1 124 2003-02-08 28 2003-05-17 -98 days
1 1 124 2003-02-08 116
Generating df1 and df2 as in your post try this (and see
http://sqldf.googlecode.com for more info):
> library(sqldf)
> out <- sqldf("select category,
+ df1.date date1,
+ df2.date date2,
+ df1.date - df2.date datediff
+ from df1 join df2 using(category)
+ order by category, date1, date2")
>
> out[
Jonathan-
When you provide an example that uses sample() or random
number generators, it's a good idea to call set.seed() before
generating the data, so that others can reproduce it.
But to answer your question:
mapply(function(d1,d2)outer(d1$date,d2$date,'-'),
split(df1,df1$ca
Hi All,
I've come up with a solution for this problem that relies on a for loop,
and I was wondering if anybody had any insight into a more elegant method:
I have two data frames, each has a column for categorical data and a column
for date. What I'd like to do, ideally, is calculate the numbe
5 matches
Mail list logo