Skip to content
Prev 275009 / 398506 Next

Calculating differences

I'd dont quite get what you are asking, but here's my best guess and
you can tweak it go get what you need.

I'd do it in two passes since you want two rather unrelated objects.

structure(list(speed = c(3,9,4,8,7,6), C = c(0.697, 0.011, 0.015,
0.012, 0.018, 0.019), house = c(1,
1, 1, 1, 1, 1), date = c(719, 1027, 1027, 1027, 1030, 1030),
   hour = c(18, 8, 8, 8, 11, 11), id = c("1000", "10000",
   "10001", "10002", "10003", "10004")), .Names = c("speed",
"C", "house", "date", "hour", "id"), class = "data.frame", row.names = c("1000",
"10000", "10001", "10002", "10003", "10004")) -> X

tapply(X, X$date, function(d) d$speed - min(d$speed))
tapply(X, X$date, function(d) d$C[which.min(d$speed)])

Michael
On Thu, Oct 20, 2011 at 5:56 PM, Jeffrey Joh <johjeffrey at hotmail.com> wrote: