For each group in a data.table, I want to repeat the value of the minimum (earliest) timestamp. Consider the following data:
library(chron)
library(data.table)
set.seed(12349870)
time.stamp<-chron(c(10000.673,sample(10001:20000,9)))
group<-c(rep(1,5),rep(2,5))
timedata<-data.table(time.stamp=time.stamp,group=group)
timedata
# 1: (05/19/97 16:09:07) 1
# 2: (03/02/21 00:00:00) 1
# 3: (02/20/15 00:00:00) 1
# 4: (12/11/10 00:00:00) 1
# 5: (08/23/10 00:00:00) 1
# 6: (07/22/18 00:00:00) 2
# 7: (06/09/23 00:00:00) 2
# 8: (03/02/13 00:00:00) 2
# 9: (06/04/09 00:00:00) 2
# 10: (12/04/12 00:00:00) 2
The following runs, but when I try to view the data.table, I get an error:
timedata[,firstdata:=time.stamp[which.min(time.stamp)],by=group]
timedata
#Error in format.dates(x, format[[1]], origin. = origin., simplify = simplify) :
#unknown date format
Session info: R version 3.1.1, chron_2.3-45, data.table_1.9.2
Do you mean it like this?