[R] extract element from list by rownames
B77S
bps0002 at auburn.edu
Tue Apr 12 17:30:39 CEST 2011
I'm thinking this isn't what you want.. but also:
> data.frame((srMT[[3]][1]))[b,][2]
filter.vel2
MK_SP1 0.2503257
SB1_SP1 0.2075117
SB4_SP1 0.2358855
B77S wrote:
>
> This probably is not ideal, but this works on a list of mine......
>
> ## so you can see the structure of my list
>> str(srMT)
> List of 4
> $ mode : chr "discrete"
> $ ks.stat : chr "mean"
> $ observed :List of 4
> ..$ filter: num [1:13, 1:4] 0.213 0.207 0.144 0.311 0.24 ...
> .. ..- attr(*, "dimnames")=List of 2
> .. .. ..$ ID_2: chr [1:13] "BC_SP1" "BU1_SP1" "BU2_SP1" "MK_SP1" ...
> .. .. ..$ : chr [1:4] "vel1" "vel2" "vel3" "vel4"
> ..$ chi2 : num [1:3] 6.93e+02 6.93e+02 1.93e-12
> ..$ df : num [1:3] 36 39 3
> ..$ p : num [1:3] 0 0 1
> $ bootstrap:List of 6
> ..$ filter : num [1:13, 1:4, 1:1000] 0.245 0.254 0.247 0.244 0.25 ...
> ##### LIST just keeps going and going and going
>
>
> # as an example
>
>> (srMT[[3]][1])
> $filter
>
> ID_2 vel1 vel2 vel3 vel4
> BC_SP1 0.2127431 0.1923574 0.2839013 0.3109983
> BU1_SP1 0.2072090 0.3094771 0.2219164 0.2613975
> BU2_SP1 0.1437481 0.3270975 0.2401788 0.2889757
> MK_SP1 0.3114887 0.2503257 0.2177326 0.2204530
> MO_SP1 0.2395539 0.2079802 0.3208321 0.2316338
> MU1_SP1 0.2336137 0.1923791 0.2386081 0.3353991
> MU2_SP1 0.3607257 0.2466847 0.1501613 0.2424284
> MU3_SP1 0.3583597 0.2499569 0.1652739 0.2264095
> RB_SP1 0.2912842 0.2742916 0.1768310 0.2575933
> SB1_SP1 0.2108506 0.2075117 0.3399161 0.2417215
> SB2_SP1 0.2910056 0.2306834 0.2507012 0.2276098
> SB4_SP1 0.2958040 0.2358855 0.2433465 0.2249641
> SC_SP1 0.2509970 0.2129797 0.3071544 0.2288689
>
>
>
>
> ## some rownames
> b <- c("MK_SP1", "SB1_SP1", "SB4_SP1")
>
> ## this works to pull them out based on row names
>
>> data.frame((srMT[[3]][1]))[b,]
> filter.vel1 filter.vel2 filter.vel3 filter.vel4
> MK_SP1 0.3114887 0.2503257 0.2177326 0.2204530
> SB1_SP1 0.2108506 0.2075117 0.3399161 0.2417215
> SB4_SP1 0.2958040 0.2358855 0.2433465 0.2249641
>
>
>
>
> I hope this helps, good luck!
>
>
>
>
>
>
> Alfredo Alessandrini wrote:
>>
>> Hi,
>>
>> I've a list of list.
>>
>> I want to extract an element by the rownames.
>>
>> I can extract it by:
>>
>> data[[1]][[1]][[4]][1]
>>
>>
>> But I want to exctract it by a command like this:
>>
>> data[[1]][["B0"]][["smac"]][["cont"]][1]
>>
>> It's possible?
>>
>>
>> Thanks,
>>
>> Alfredo
>>
>>
>>
>>
>>> str(data)
>> List of 1
>> $ :List of 4
>> ..$ :List of 4
>> .. ..$ : num [1, 1:3] 0.4 0.458 0.5
>> .. ..$ : num [1:41, 1] 0.4 0.403 0.405 0.407 0.41 ...
>> .. ..$ : num [1:41, 1] 0.000128 0.000328 0.000528 0.000728 0.000992 ...
>> .. ..$ :List of 1
>> .. .. ..$ : num [1:49, 1] 0 0 -0.00626 0.99832 0 ...
>> .. .. ..- attr(*, "dim")= int [1:3] 1 1 1
>> .. .. ..- attr(*, "dimnames")=List of 3
>> .. .. .. ..$ : chr "cont"
>> .. .. .. ..$ : NULL
>> .. .. .. ..$ : NULL
>> .. ..- attr(*, "dim")= int [1:3] 4 1 1
>> .. ..- attr(*, "dimnames")=List of 3
>> .. .. ..$ : chr [1:4] "begin.mode.end" "lambda" "sensi" "smac"
>> .. .. ..$ : NULL
>> .. .. ..$ : NULL
>> ..$ :List of 4
>> .. ..$ : num [1, 1:3] 0.58 0.67 0.782
>> .. ..$ : num [1:82, 1] 0.58 0.583 0.585 0.588 0.59 ...
>> .. ..$ : num [1:82, 1] 0.0017 0.00168 0.00165 0.00162 0.0016 ...
>> .. ..$ :List of 1
>> .. .. ..$ : num [1:49, 1] -0.00597 0.71045 -0.05844 0.99187 -0.00807
>> ...
>> .. .. ..- attr(*, "dim")= int [1:3] 1 1 1
>> .. .. ..- attr(*, "dimnames")=List of 3
>> .. .. .. ..$ : chr "cont"
>> .. .. .. ..$ : NULL
>> .. .. .. ..$ : NULL
>> .. ..- attr(*, "dim")= int [1:3] 4 1 1
>> .. ..- attr(*, "dimnames")=List of 3
>> .. .. ..$ : chr [1:4] "begin.mode.end" "lambda" "sensi" "smac"
>> .. .. ..$ : NULL
>> .. .. ..$ : NULL
>> ..$ :List of 4
>> .. ..$ : num [1, 1:3] 0.7 0.82 1.03
>> .. ..$ : num [1:133, 1] 0.7 0.703 0.705 0.708 0.71 ...
>> .. ..$ : num [1:133, 1] 0.0007 0.000775 0.00085 0.000925 0.001 ...
>> .. ..$ :List of 1
>> .. .. ..$ : num [1:49, 1] -0.030584 0.559164 -0.000269 0.995624
>> -0.006616 ...
>> .. .. ..- attr(*, "dim")= int [1:3] 1 1 1
>> .. .. ..- attr(*, "dimnames")=List of 3
>> .. .. .. ..$ : chr "cont"
>> .. .. .. ..$ : NULL
>> .. .. .. ..$ : NULL
>> .. ..- attr(*, "dim")= int [1:3] 4 1 1
>> .. ..- attr(*, "dimnames")=List of 3
>> .. .. ..$ : chr [1:4] "begin.mode.end" "lambda" "sensi" "smac"
>> .. .. ..$ : NULL
>> .. .. ..$ : NULL
>> ..$ :List of 4
>> .. ..$ : num [1, 1:3] 1.45 1.64 1.8
>> .. ..$ : num [1:141, 1] 1.45 1.45 1.46 1.46 1.46 ...
>> .. ..$ : num [1:141, 1] 0.001 0.001 0.001 0.001 0.001 ...
>> .. ..$ :List of 1
>> .. .. ..$ : num [1:49, 1] -0.00547 0.65798 0 0 0 ...
>> .. .. ..- attr(*, "dim")= int [1:3] 1 1 1
>> .. .. ..- attr(*, "dimnames")=List of 3
>> .. .. .. ..$ : chr "cont"
>> .. .. .. ..$ : NULL
>> .. .. .. ..$ : NULL
>> .. ..- attr(*, "dim")= int [1:3] 4 1 1
>> .. ..- attr(*, "dimnames")=List of 3
>> .. .. ..$ : chr [1:4] "begin.mode.end" "lambda" "sensi" "smac"
>> .. .. ..$ : NULL
>> .. .. ..$ : NULL
>> ..- attr(*, "dim")= int [1:3] 4 1 1
>> ..- attr(*, "dimnames")=List of 3
>> .. ..$ : chr [1:4] "B0" "B2" "B3" "MIR"
>> .. ..$ : NULL
>> .. ..$ : NULL
>>>
>>
>> ______________________________________________
>> 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.
>>
>
--
View this message in context: http://r.789695.n4.nabble.com/extract-element-from-list-by-rownames-tp3444730p3444918.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list