r - Datetime problem when using Lubridate function
问题描述
Code to reconstruct the df:
rdf=structure(list(caseid = c("60",
"76", "33", "76", "33", "12", "35",
"88", "32", "44"), indate = c("2020-05-05 17:41:28.277",
"2020-08-31 03:29:31.110", "2020-10-13 09:34:00.887", "2020-08-21 11:51:18.157",
"2020-10-13 09:34:12.173", "2020-08-06 11:55:30.857", "2019-12-17 15:02:05.747",
"2019-11-22 10:12:29.247", "2020-05-16 01:27:17.960", "2020-07-04 19:47:50.587"
),countryid = c("TAIWAN",
"INDIA", "SINGAPORE", "TAIWAN", "SINGAPORE", "SINGAPORE", "HONG KONG",
"SINGAPORE", "SINGAPORE", "INDIA")), .Names = c("caseid", "indate", "countryid"), row.names = c(NA, 10L
), class = "data.frame")
rdf$indate = as.factor(rdf$indate)
Code to add 6 hours to indate when country is equal to Hong Kong and Macau.
library(dplyr)
library(lubridate)
rdf <- rdf %>%
mutate(indate = ymd_hms(indate)
,indate1 = if_else(countryid %in% c('HONG KONG','MACAU'), indate + hours(6), indate) )
rdf$indate = NULL
colnames(rdf)[6]='indate'
rdf = rdf[c("casenumber","caseid","indate","actiondate","countryid","caseflowid")]
When using this dataframe for a new function getting the below error:
Error in charToDate(x) :
character string is not in a standard unambiguous format
解决方案
推荐阅读
- asp.net-core - Core Razor Pages - Id 未在模态包装的表单上发布
- json - JSON 数组作为 TableView 中的对象
- php - 使用 PHP 仅获取 mysql 查询的最后一行
- kotlin - 使用 Retrofit2 在 Recyclerview 中未设置 Gson 转换的数据
- r - 计算两个日期时间之间 15 分钟的序列出现
- r - 将 PCR 96 孔板转换为单列格式
- sql - 如何更改存储在 Postgres 中的 JSON 对象中所有记录的键名
- loops - Applescript:循环中的文本定界
- javascript - 从 Firebase 获取图片网址
- julia - ```@time``` 范围内的 UndefVarError 错误