[Rd] Lists and data frames (PR#8143)
Uwe Ligges
ligges at statistik.uni-dortmund.de
Mon Sep 19 16:39:57 CEST 2005
Gavin Simpson wrote:
> On Mon, 2005-09-19 at 15:34 +0200, fwagner at fh-lausitz.de wrote:
>
>>Full_Name: Frank Wagner
>>Version: R 2.1.1
>>OS: Windows
>>Submission from: (NULL) (193.174.73.34)
>>
>>
>>Hi,
>>The pdf file R-intro descripe on page 27 that lists can be extended by adding
>>numbers.
>>Unfortunately, it's not working
>>## example :
>>
>># if i did not declare the variable an error occurs : object not found
>>mylist <- list()
>>mylist[1] <- list(value1=3, value2=5)
>>## Error
>
>
> You need to use [[x]] to subset a list:
>
>
>>mylist <- list()
>>mylist[[1]] <- list(value1=3, value2=5)
>>mylist
>
> [[1]]
> [[1]]$value1
> [1] 3
>
> [[1]]$value2
> [1] 5
This is a list of a list, but that is not the same as the stuff we are
discussing here. See below.
>
>>str(mylist)
>
> List of 1
> $ :List of 2
> ..$ value1: num 3
> ..$ value2: num 5
>
> I don't know whether there is a typo on page 27 or not: [x] is valid, it
> just means something different to [[x]] - as explained on page 26 of
> said manual. If it was intentional, then IMHO it is not the most clear
> example of extending a list - the [[x]] notation is what I would expect
> to have to use - after reading page 26 of course...
Folks, please specify which version of the manual you are speaking
about, e.g. by giving a chapter's/section's name.
The statement on what is referred to page 27 in this thread is completly
correct.
Note that a list is nothing else than a vector of mode list which
contains in each element a list of length one.
Hence you *can* say
mylist[1:2] <- list(value1=3, value2=5)
or
c(mylist, list(value1=3, value2=5))
or whatever.
Uwe Ligges
> HTH
>
> G
More information about the R-devel
mailing list