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 Can you please help me Thank you Regards Frank Wagner
> From: r-devel > > 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) > ## ErrorI don't get that (with R-2.1.1-patched on WinXPPro): R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 Patched (2005-07-13), ISBN 3-900051-07-0 [...]> mylist <- list() > mylist[1] <- list(value1=3, value2=5)Warning message: number of items to replace is not a multiple of replacement length Andy> Can you please help me > Thank you > > Regards > Frank Wagner > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > >
ligges@statistik.uni-dortmund.de
2005-Sep-19 13:58 UTC
[Rd] Lists and data frames (PR#8143)
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) > ## ErrorNO! 1. No, this is not a bug! 2. No, this was not an error but a *warning* which tells you that the length does not match. Each Element of *vector* mylist must be a list of length one, hence you cannot assign one of length two. Instead you can say: mylist[1:2] <- list(value1=3, value2=5) This is a question that might go to R-help, if you do not understand what is described in the docs. The manual is correct, hence this is not a bug. Please read the docs on how to post bugs and how a bug is defined ... Uwe Ligges> > Can you please help me > Thank you > > Regards > Frank Wagner > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
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) > ## ErrorYou 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. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%