【发布时间】:2021-09-14 17:48:12
【问题描述】:
我有一个虚拟数据框,它在 POSIXct 中包含 10 个日期时间戳。现在我想评估每一行,如果高于日期时间阈值,则将单元格值替换为不同的值,否则保留它。我使用 dplyr 包找到了一个有用的线程here,但我无法让它适用于我的特殊情况。有什么建议吗?
虚拟数据框的代码:
df<-structure(list(Date.Out = structure(c(1478699520, 1493934000,
1510243080, 1524862800, 1541776440, 1559243220, 1475417460, 1493930940,
1495304760, 1504640100), class = c("POSIXct", "POSIXt"), tzone = "US/Eastern")), row.names = c(6L,
7L, 8L, 9L, 10L, 11L, 15L, 16L, 17L, 18L), class = "data.frame")
我尝试使用不起作用的 dplyr 包的代码:
df %>%
mutate(new = as.POSIXct(ifelse(Date.Out>="2019-05-01 00:00:00", "2019-05-01 00:00:00", Date.Out), origin='1970-01-01', na.rm=T))
【问题讨论】:
标签: r if-statement dplyr