[R] list manipulation

David Winsemius dwinsemius at comcast.net
Sun Dec 12 19:32:48 CET 2010


On Dec 12, 2010, at 1:18 PM, andrija djurovic wrote:

> Hi R users!
> Does anyone know command similar to cbind for adding a column to a  
> object of
> the list. For example on this list:
>> c1
> $`1`
> x11 x22
> 1 1 1
> 2 1 2
> 3 1 3
> 4 1 4
> 5 1 5

So item `1` is probably a data.frame.

>
> $`2`
> x11 x22
> 6 2 6
> 7 2 7
> 8 2 8
> 9 2 9
> 10 2 10
> 11 2 11
> i would like to add column, named random created with - runif(5)-,  
> to the
> first object in order to obtain something like this:
>> c1
> $`1`
> x11 x22 random
> 1 1 1      0.5624256
> 2 1 2       0.6752097
> 3 1 3      0.1005275
> 4 1 4      0.3325556
> 5 1 5      0.7650282

Try c1[[1]] <- cbind(c1[[1]], runif(5))

(Untested. I supposed you could argue that you had provided a  
reproducible example, but going through the hoops of creating two such  
dataframes and then creating a list to hold them seems something that  
you should have provided code for rather than posting just console  
output.)

-- 
David.
>
>
> $`2`
> x11 x22
> 6 2 6
> 7 2 7
> 8 2 8
> 9 2 9
> 10 2 10
> 11 2 11

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list