[R] Container/Collection Object to keep data structures and object

Sharpie chuck at sharpsteen.net
Wed Dec 2 03:08:06 CET 2009



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!

-Charlie
-- 
View this message in context: http://n4.nabble.com/Container-Collection-Object-to-keep-data-structures-and-object-tp932656p932693.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list