« first day (1337 days earlier)      last day (1962 days later) » 

12:03 AM
tool / package request: stackoverflow.com/q/53841658/5977215
 
 
6 hours later…
5:57 AM
27 messages moved to Trash can
 
 
2 hours later…
7:37 AM
good morning all
 
 
1 hour later…
8:38 AM
hello :-)
 
 
4 hours later…
12:54 PM
Hello hello :-)
 
 
1 hour later…
2:06 PM
 
2:44 PM
df <- structure(list(name = c("a", "a", "b", "b", "c", "c"), new_date = structure(c(17591,
17563, 17318, 17257, 17775, 17379), class = "Date")), .Names = c("name",
"new_date"), row.names = c(NA, -6L), class = "data.frame")
For the above data ---^ does anybody know why
with(df, ave(new_date, name, FUN = max)) works and
with(df, ave(new_date, name, FUN = which.max)) does not ?
 
@RonakShah try with(df, ave(new_date, name, FUN = function(x) x[which.max(x)])) ;-)
 
I was going to say that it needs to return integers so it fails in converting dates to numerics, but then this with(df, ave(new_date, name, FUN = function(i) i == max(i))) does not work either
 
but then what's wrong with which.max? :(
Dates are internally numbers as well, right?
 
yup
no idea though...
 
@RonakShah but they need an origin ;-p
 
2:58 PM
ask it...
The title of this question sounds so wrong!
:)
 
@RonakShah key is in split(df$new_date, df$name) <- lapply(split(df$new_date, df$name), which.max) in ave function, using as.Date.numeric, it needs a date to replace and cannot coerce to it as is (or I think this is the problem...)
yep that's the problem : the method split<- used on a vector works by replacing the value of x with the value of FUN(x) on a specific place. In your case, x is a vector of date and it tries to replace one of the value with a numeric (x[i] <- value[[j]]), which does not work
 
3:21 PM
Aaand I m off to my daughter's very first school play!!! :D
#proudDad:)
 
@Sotos don't forget the camera ^^ and have fun :-)
 

« first day (1337 days earlier)      last day (1962 days later) »