如果在 R 中使用 strptime,则输入字符串太长错误
Input string too long error if using strptime in R
我的文件包含时间戳列表:
Fri Feb 14 19:07:31 +0000 2014
Fri Feb 14 19:07:46 +0000 2014
Fri Feb 14 19:07:50 +0000 2014
Fri Feb 14 19:08:04 +0000 2014
并使用以下方法将其读入 R:
dataset <- read.csv(file="Data.csv")
然后我编写 R 命令以使 R 能够检测时间戳:
time <- strptime(dataset,format = "%a %b %d %H:%M:%S %z %Y", tz = "GMT")
但我经常收到一条错误消息:
Error in strptime(dataset, format = "%a %b %d %H:%M:%S %z %Y") :
input string is too long
一开始它运行良好,但在我添加之后:
defaults write org.R-project.R force.LANG en_US.UTF-8
在我的终端中为 mac os x 修复 R 中的一些首选项,timestamp 命令停止工作并继续产生我上面提到的错误。
这是您的原始数据。 myDates 作为角色。
dtData<-data.frame(myDates=c( "Fri Feb 14 19:07:31 +0000 2014",
"Fri Feb 14 19:07:46 +0000 2014",
"Fri Feb 14 19:07:50 +0000 2014",
"Fri Feb 14 19:08:04 +0000 2014"))
> dtData
myDates
1 Fri Feb 14 19:07:31 +0000 2014
2 Fri Feb 14 19:07:46 +0000 2014
3 Fri Feb 14 19:07:50 +0000 2014
4 Fri Feb 14 19:08:04 +0000 2014
您需要 select dtData$myDates 列
time <- strptime(dtData$myDates,format = "%a %b %d %H:%M:%S %z %Y", tz = "GMT");time
[1] "2014-02-14 19:07:31 GMT" "2014-02-14 19:07:46 GMT"
[3] "2014-02-14 19:07:50 GMT" "2014-02-14 19:08:04 GMT"
我的文件包含时间戳列表:
Fri Feb 14 19:07:31 +0000 2014
Fri Feb 14 19:07:46 +0000 2014
Fri Feb 14 19:07:50 +0000 2014
Fri Feb 14 19:08:04 +0000 2014
并使用以下方法将其读入 R:
dataset <- read.csv(file="Data.csv")
然后我编写 R 命令以使 R 能够检测时间戳:
time <- strptime(dataset,format = "%a %b %d %H:%M:%S %z %Y", tz = "GMT")
但我经常收到一条错误消息:
Error in strptime(dataset, format = "%a %b %d %H:%M:%S %z %Y") :
input string is too long
一开始它运行良好,但在我添加之后:
defaults write org.R-project.R force.LANG en_US.UTF-8
在我的终端中为 mac os x 修复 R 中的一些首选项,timestamp 命令停止工作并继续产生我上面提到的错误。
这是您的原始数据。 myDates 作为角色。
dtData<-data.frame(myDates=c( "Fri Feb 14 19:07:31 +0000 2014",
"Fri Feb 14 19:07:46 +0000 2014",
"Fri Feb 14 19:07:50 +0000 2014",
"Fri Feb 14 19:08:04 +0000 2014"))
> dtData
myDates
1 Fri Feb 14 19:07:31 +0000 2014
2 Fri Feb 14 19:07:46 +0000 2014
3 Fri Feb 14 19:07:50 +0000 2014
4 Fri Feb 14 19:08:04 +0000 2014
您需要 select dtData$myDates 列
time <- strptime(dtData$myDates,format = "%a %b %d %H:%M:%S %z %Y", tz = "GMT");time
[1] "2014-02-14 19:07:31 GMT" "2014-02-14 19:07:46 GMT"
[3] "2014-02-14 19:07:50 GMT" "2014-02-14 19:08:04 GMT"