Message-ID: <1127138624.31636.6.camel@gsimpson.geog.ucl.ac.uk>
Date: 2005-09-19T14:03:44Z
From: Gavin Simpson
Subject: Lists and data frames (PR#8143)
In-Reply-To: <20050919133405.D29FD1C6B0@slim.kubism.ku.dk>
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
> 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...
HTH
G
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [T] +44 (0)20 7679 5522
ENSIS Research Fellow [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk
UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/
London. WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%