我想根据最近的日期更新dt中的值。
dt <- data.table(Name=c('John Smith', 'John Doe', 'Jeff Smith'),
State=c('MI','WI','WI'),
Date = c("2018-1-2", "2018-1-4", "2018-1-6"),
stringsAsFactors=F)
这有效:
dt[State == "WI" & Date == dt[which.max(as.POSIXct(Date)), Date], Name := paste0(Name, "3")]