[英]R: $ operator invalid for atomic vectors Error with POSIX
i may be missing something really obvious here, could you help me? 我可能会在这里遗漏一些非常明显的东西,您能帮我吗?
when i send a date object to seLocalize() function, it returns me as expected for the code that follows (i sent 14-mar-18 and returned 13-mar-18) 当我将日期对象发送到seLocalize()函数时,它按预期返回以下代码(我发送了18-mar-18并返回了13-mar-18)
seLocalize <- function(dataTeste) {
data <- as.POSIXlt(dataTeste)
if(data$wday != 0) {
data <- data-86400
}
print(data)
}
Although, for following the piece of code, the same test returns "Error: $ operator is invalid for atomic vectors" 尽管对于遵循这段代码,相同的测试返回“错误:$运算符对原子向量无效”
seLocalize <- function(dataTeste) {
data <- as.POSIXlt(dataTeste)
while(data$wday != 0) {
data <- data-86400
}
print(data)
}
Why? 为什么?
I'm having troubles believing this is a proper problem description since that date was in a format that would not be recognized. 我很难相信这是一个正确的问题描述,因为该日期的格式无法识别。
> seLocalize <- function(dataTeste) {
+ data <- as.POSIXlt(dataTeste)
+ while(data$wday != 0) {
+ data <- data-86400
+ }
+ print(data)
+ }
> seLocalize("13-mar-18")
Error in as.POSIXlt.character(dataTeste) :
character string is not in a standard unambiguous format
So I tried sending what I thought was a possible revised function (for the somewhat obscure coercion induced error ) a proper date value for as.POSIXlt
: 因此,我尝试为
as.POSIXlt
发送一个我认为是可能的修订函数(因为有些晦涩的强制性错误)了一个正确的日期值:
seLocalize2 <- function(dataTeste) {
data <- as.POSIXlt(dataTeste)
while(data$wday != 0) {
data <- as.POSIXlt(data-86400) # coerce back to POSIXlt
}
print(data)
}
> seLocalize2("2018-03-25")
[1] "2018-03-25 PDT"
> seLocalize2("2018-03-29")
[1] "2018-03-25 PDT"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.