我想基于另一个ID和时间戳创建一个“timeID”列...我正在使用data.table :: setorder()而且我大部分都在那里,但timeID列只是使用时间戳值而不是时间ID(1,2,3,... n)填充。图像是我当前的输出......
我在这里缺少什么?
# Parse timestamp
df1[, Month := str_sub(df1$BaseTimeStamp, 4,6)]
df1[, Year := str_sub(df1$BaseTimeStamp, 8,11)]
df1[, Day := str_sub(df1$BaseTimeStamp, 1,2)]
df1[, Hour := str_sub(df1$BaseTimeStamp, 13,14)]
df1[, Min := str_sub(df1$BaseTimeStamp, 16,17)]
df1[, Sec := str_sub(df1$BaseTimeStamp, 19,20)]
df1[, timeParse := ymd_hms(paste(df1$Year,
df1$Month,
df1$Day,
df1$Hour,
df1$Min,
df1$Sec))]
# Create timeStamp ID
df1[, timeID := setorder(df1, myID, timeParse), by = myID]