返回的对象nls()
是一个列表。on a list的行为is.na()
在 what is an is not 的意义上有些特殊NA
。来自?is.na
:
Value:
The default method for ‘is.na’ applied to an atomic vector returns
a logical vector of the same length as its argument ‘x’,
containing ‘TRUE’ for those elements marked ‘NA’ or, for numeric
or complex vectors, ‘NaN’ (!) and ‘FALSE’ otherwise. ‘dim’,
‘dimnames’ and ‘names’ attributes are preserved.
The default method also works for lists and pairlists: the result
for an element is false unless that element is a length-one atomic
vector and the single element of that vector is regarded as ‘NA’
or ‘NaN’.
根据上面引用的文本确定的t
逻辑向量也是如此TRUE
。因此所有FALSE
t
t[1]
t["m"]
head(t, 1)
提取 的第一个元素t
。如果您想测试,FALSE
那么我可以尝试:
!isTRUE(t[1])
例如
> set.seed(1)
> logi <- sample(c(TRUE,FALSE), 5, replace = TRUE)
> logi
[1] TRUE TRUE FALSE FALSE TRUE
> !isTRUE(logi[1])
[1] FALSE
该$
版本不起作用的原因$
是记录仅适用于非原子向量。logi
(或你的t
)是一个原子向量,因为它包含相同类型的元素。
> is.atomic(logi)
[1] TRUE
> names(logi) <- letters[1:5]
> logi$a
Error in logi$a : $ operator is invalid for atomic vectors
> logi["a"]
a
TRUE