0

我有large POSIXct大约 70,000 个元素。

resolutionDate <- c(as.POSIXct(data$Resolution.Date, format = '%b %d, %Y'))

上面的代码将值从 更改Jun 5, 2018 3:21 PM2018-06-05

但是,有些值是NA,我想用 , 替换今天的所有NASys.time()

我尝试使用这种replace()方法, replace(resolutionDate, if(resolutionData == "NA"), Sys.time())

但是没用。。

我怎样才能做到这一点?

4

1 回答 1

1

像这样的东西?

# generate time vector
a <- as.POSIXct(1:70000,origin="1970-01-01")
# replace the 5th with a NA value and show first 10 elements
a[5] <- NA
a[1:10]
# replace all na values with the current system time
a[is.na(a)] <- Sys.time()
# show result
a[1:10]
于 2018-06-08T14:47:41.053 回答