[R] column selection in list

baptiste auguie baptiste.auguie at googlemail.com
Fri Jan 22 17:19:40 CET 2010


Hi,

Try this,

a = replicate(3, data.frame(x=1:10, y=rnorm(10)), simplify=FALSE)

lapply(a, "[", "y")

HTH,

baptiste

2010/1/22 Ivan Calandra <ivan.calandra at uni-hamburg.de>:
> Hi everybody!
>
> I have a (stupid) question but I cannot find a way to do it!
>
> I have a list like:
>> SPECSHOR_tx_Asfc
> $cotau
>   SPECSHOR Asfc.median
> 38    cotau    381.0247
> 39    cotau    154.6280
> 40    cotau    303.3219
> 41    cotau    351.2933
> 42    cotau    156.5327
> $eqgre
>    SPECSHOR Asfc.median
> 145    eqgre    219.5389
> 146    eqgre    162.5926
> 147    eqgre    146.3726
> 148    eqgre    127.6413
> 149    eqgre    274.2888
> $gicam
>    SPECSHOR Asfc.median
> 263    gicam    174.7445
> 264    gicam     83.4821
> 265    gicam    157.6005
> 266    gicam    153.7519
> 267    gicam    344.9775
>
> I would just like to remove the column "SPECSHOR" (or extract the other one)
> so that it looks like
> $cotau
>    Asfc.median
> 38        381.0247
> 39       154.6280
> 40        303.3219
> 41        351.2933
> 42        156.5327
> etc.
>
> How should I do it? I know how to select each element like
> SPECSHOR_tx_Asfc[[1]], but I don't know how to select a single column within
> an element.
>
> Could you please help me on that?
>
> Thanks
> Ivan
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list