false vs. f:错误mapply' s简化参数:在简化= f中
这个问题是指此有没有最好的方法将列表值附加到r?中的列表的sublist。
解决方案之一是:
a <- list(3,5,7)
l <- list(c(1,2,3), c(2,1,4), c(4,7,6))
mapply(c, l, a, SIMPLIFY=F)
如果我尝试将其应用于我的计算机上,则会发现错误:
Error in SIMPLIFY == "array" :
comparison (1) is possible only for atomic and list types
如果使用此错误 - &gt;没有错误:
mapply(c, l, a, SIMPLIFY = FALSE)
我想了解为什么在使用Simplify = F而不是在Simplify = false
中发生错误。
我正在使用rstudio -cloud:
> version
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 4
minor 1.3
year 2022
month 03
day 10
svn rev 81868
language R
version.string R version 4.1.3 (2022-03-10)
nickname One Push-Up
This Question refers to this Is there a best way to append a list values to a sublist of a list in R?.
One of the solution is this:
a <- list(3,5,7)
l <- list(c(1,2,3), c(2,1,4), c(4,7,6))
mapply(c, l, a, SIMPLIFY=F)
If I try to apply it on my machine I get the error:
Error in SIMPLIFY == "array" :
comparison (1) is possible only for atomic and list types
If I use this -> there is no error:
mapply(c, l, a, SIMPLIFY = FALSE)
I want to understand why the error occurs in using SIMPLIFY =F and not in SIMPLIFY = FALSE
.
I am using rstudio - cloud:
> version
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 4
minor 1.3
year 2022
month 03
day 10
svn rev 81868
language R
version.string R version 4.1.3 (2022-03-10)
nickname One Push-Up
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在全新的r会话中,此错误不可重复:
但是,我们可以通过函数覆盖
f
来复制您的错误:这表明您在搜索路径上的某个位置,称为
> f
。我们可以猜到它是一个函数而不是数据框架或向量的原因,是因为只有将某些内容传递给
Simplefify
没有一个没有一个没有的错误 则函数是最有可能的候选者(尤其是因为它称为f
)为
==
运算符定义的方法,并且如果您查看mapply的源代码,
,您会看到Simplify
参数将传递到Simplefify2Array
时,并且仅当它未对Atomicfalse false
:如果它不是原子
false
,则使用==进行测试,对
操作员。如果无法用字符串测试对象的平等,我们将获得此错误。简化
参数进行等于字符串“ array”
我认为这个问题是一个很好的例子,说明为什么永远不要将
f
用作R中的变量名称,以及为什么人们应该始终使用false
而不是f
f
。 /代码>。
In a fresh R session, this error isn't reproducible:
However, we can replicate your error by overwriting
F
with a function:Which suggests that you have a function somewhere on your search path called
F
.The reason that we can guess it is a function rather than, say, a data frame or a vector, is that we would only get this error if there is something being passed to
SIMPLIFY
that does not have a method defined for the==
operator, and a function is the most likely candidate (especially since it is calledF
)If you look at the source code for
mapply
, you will see that theSIMPLIFY
argument gets passed tosimplify2array
if and only if it does not evaluate to an atomicFALSE
:If it is not an atomic
FALSE
, theSIMPLIFY
argument is then tested for equality to the string"array"
using the==
operator. If the object cannot be tested for equality with a character string, we will get this error.I think this question is a great example of why one should never use
F
as a variable name in R, and why one should always useFALSE
instead ofF
.正如OP提到的那样,它们在控制台中没有创建任何功能
f
,它可能来自加载collapse
package,然后我们检查
?f
因此,可以重现该错误
As the OP mentioned that they didn't create any function
F
in the console, it could be coming from loadingcollapse
packageand then we check
?F
Thus, the error can be reproduced