によって返されるオブジェクトはnls()
リストです。リスト上のの振る舞いはis.na()
、何がそうではないかという意味でやや独特です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
$
バージョンが機能しない理由は、非アトミックベクトルにのみ$
適用されるように文書化されているためです。(またはyour )は、同じタイプの要素を含むという点でアトミックベクトルです。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