我正在尝试将时间转换为自午夜以来的秒数。我很难从 chron 包中获取 times() 函数来工作。我的使用方法如下:
> library(chron)
> 24 * 24 * 60 * (times(50))
Error in 24 * 24 * 60 * (times(50)) :
non-numeric argument to binary operator
>
>
> library(chron)
> 24 * 24 * 60 times(5000)
Error: unexpected symbol in "24 * 24 * 60 times"
有什么建议么?
UPDATE:
> sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RODBC_1.3-3 nnet_7.3-1 doSNOW_1.0.3 foreach_1.3.0
[5] codetools_0.2-8 iterators_1.0.3 snow_0.3-7 randomForest_4.6-2
[9] chron_2.3-42
loaded via a namespace (and not attached):
[1] tools_2.14.0
更新2:
> find("times")
[1] "package:foreach" "package:chron"
> times
function (n)
{
if (!is.numeric(n) || length(n) != 1)
stop("n must be a numeric value")
foreach(icount(n), .combine = "c")
}
<environment: namespace:foreach>
更新3:
> sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] chron_2.3-42
> find("times")
[1] "package:chron"
> 24 * 24 * 60 * (times * (50))
Error in times * (50) : non-numeric argument to binary operator
问题是package:foreach
还包含一个名为的函数times
。而且因为它出现在之前package:chron
在您的搜索路径上,它“掩盖”了times
你真正想要的功能。
换句话说,当 R 执行动态搜索符号时times
,它会在到达与您想要查找的函数关联的匹配项之前找到匹配项(在本例中是错误的匹配项)。
您可以通过启动新的 R 会话,然后输入以下内容来查看这一点:
> library(chron)
> library(foreach)
Loading required package: iterators
Loading required package: codetools
foreach: simple, scalable parallel programming from Revolution Analytics
Use Revolution R for scalability, fault tolerance and more.
http://www.revolutionanalytics.com
Attaching package: ‘foreach’
The following object(s) are masked from ‘package:chron’:
times
If you do需要附加两个包,您可以确保您获得正确的版本times()
通过以下任一方法: 颠倒软件包的附加顺序(可以,但不太好);或者(更好)通过键入明确指定您想要的功能chron::times
, as in:
24 * 24 * 60 * (chron::times(50))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)