[R] Container/Collection Object to keep data structures and object
Rolf Turner
r.turner at auckland.ac.nz
Wed Dec 2 03:18:31 CET 2009
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}}
More information about the R-help
mailing list