[R] Is it a bug in list() behavior?
Tony Plate
tplate at blackmesacapital.com
Mon Mar 24 18:47:06 CET 2003
As wolski/Eryk's example shows, it seems that "[[" for lists accepts abbreviations, whereas "[" does not. Is this intended? (This is a difference from S-plus - both "[" and "[[" for lists accept abbreviations in S-plus (V6.1 for Windows at least.)
I couldn't find any mention of this difference in regards to accepting abbreviations in either ?"[" or section 6.1 of the Introduction to R, or in the R Language Manual, or in the R Reference Manual. [As an aside, I'd rather that the subset operators didn't accept abbreviations at all,but ...]
The name returned by "[" for a non-existent element of a list also seems of dubious correctness.
> list(abc=123)[["a"]]
[1] 123
> list(abc=123)["a"]
$"NA"
NULL
> list(abc=123)$a
[1] 123
> version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 1
minor 6.2
year 2003
month 01
day 10
language R
>
At Monday 04:54 PM 3/24/2003 +0100, you wrote:
>wolski wrote:
>>Hello!
>>let:
>>test<-1:3
>>list(test)
>>names(test)<-c("X11","X12","Y23")
>>
>>>test[["Y2"]]
>>3
>>I had assumed that the names in a list are like a keys in a hash.
>>Therefore i thought that no value should be returned.
>>The behavior of:
>>
>>>test["Y2"]
>><NA> NA
>>is as i expected.
>>
>>Should it be as it is? How is the definition of [[]] and []?
>
>No! See "An Introduction to R", Section 6.1:
>"The names of components may be abbreviated down to the minimum number of letters needed to identify them uniquely. Thus Lst$coefficients may be minimally specified as Lst$coe and Lst$covariance as Lst$cov."
>
>Uwe Ligges
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list