[英]R chron times() function won't work
我正試圖將時間從午夜轉換為秒。 我很難從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"
有什么建議?
更新:
> 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
如果你確實需要附加兩個軟件包,你可以通過以下方式確保獲得正確的times()
版本:反轉軟件包的連接順序(OK但不是很好); 或者(更好)通過鍵入chron::times
顯式指定所需的函數,如:
24 * 24 * 60 * (chron::times(50))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.