你能帮我弄清楚为什么以下不起作用吗?我有一个 2528x3 矩阵 uniqueitems,如下所示:
Number Created Customer
=========== =================== ============
31464686486 2013-10-25 10:00:00 john@john.de
...
我想做的事情:遍历每一行,检查 Created 是否比给定时间更新,如果是,则将该行写入新表 newerthantable。这是我的代码:
library(lubridate);
newerthan <- function(x) {
times <- ymd_hms(uniqueitems[,2])
newerthantable <- matrix(data=NA,ncol=3,nrow=1)
i <- 1;
while (i <= nrow(uniqueitems)) {
if (x < times[i]) {
newerthantable <- rbind(newerthantable,uniqueitems[i,])
}
i <- i + 1;
}
}
但是 newerthan("2013-10-24 14:00:00") 没有达到预期的效果:(,没有任何东西写在 newerthantable 中。为什么?