我的脚本中的以下行
gather(key = var, value = val, which(names(somevar) == "somestring"):length(somevar))
抛出错误
Error in which(names(somevar) == "somestring") :
could not find function "which"
当我在控制台中编写which
时,输出仍然如下......
> which
function (x, arr.ind = FALSE, useNames = TRUE)
{
wh <- .Internal(which(x))
if (arr.ind && !is.null(d <- dim(x)))
arrayInd(wh, d, dimnames(x), useNames = useNames)
else wh
}
<bytecode: 0x0000000006c6e258>
<environment: namespace:base>
我应该在哪里了解如何解决问题?
PS。 base
(包含which
函数)包已安装。 extrafont
脚本中加载了tools
,tidyr
,dplyr
,readxl
个包。 R
版本为3.4.1
,系统为Win8
。
UPD。代码
somevar <- data.frame(v1 = 1:5, somestring = 6:10, v3 = 11:15, v4 = 16:20);
somevar %>% gather(key = var, value = val, which(names(somevar) == "somestring"):length(somevar)) %>% head(2);
引发同样的错误...
Error in which(names(somevar) == "somestring") :
could not find function "which"