On 2/12/2009, at 3:08 PM, Sharpie wrote:



Amir Liu wrote:

In l[3] <- matrix(1:4, 2, 2) :
  number of items to replace is not a multiple of replacement length


When inserting single entries into a list list, you should use the '[[ ]]'
notation.  Use '[ ]' when you want to extract multiple entries or copy
multiple entries from one list to another:

  l <- list()
  l[[ 1 ]] <- 5
  l[[ 2 ]] <- 'cd'
  l[[ 3 ]] <- matrix( 1:4, 2, 2 )

  l
  [[1]]
  [1] 5

  [[2]]
  [1] "cd"

  [[3]]
        [,1] [,2]
  [1,]    1    3
  [2,]    2    4

Hope this helps!

The key issue is that l[3] is a ***list*** of length 1 whose single entry is the object that was the third entry of ``l''. But l[[3]] is ***the object*** that was the third entry of ``l''. It's like the difference a box containing
the third chocolate from a box of chocolates and that third chocolate.

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to