[R] How to access data structure (List of List)
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Mon Jun 23 09:34:05 CEST 2008
Gundala Viswanath wrote:
> Hi,
>
> I have this kind of output.
>
>
>> str(nw)
>>
> List of 3
> $ :List of 2
> ..$ part1: num 30.9
> ..$ part2: num [1:78] 60.1 70.0 73.0 75.0 83.9 ...
> $ :List of 2
> ..$ part1: num [1:2] 30.9 60.1
> ..$ part2: num [1:77] 70.0 73.0 75.0 83.9 93.1 ...
> $ :List of 2
> ..$ part1: num [1:3] 30.9 60.1 70
> ..$ part2: num [1:76] 73.0 75.0 83.9 93.1 97.6 ...
>
> My question are:
>
> 1. What kind of data structure is it? List of List?
> 2. How can I access it's element?
>
> I tried the following loop but seem to fail
>
> for (i in 1:length(nw)) {
> print(nw[i]$part1)
> }
>
>
Try
for (i in 1:length(nw)) {
print(nw[[i]]$part1)
}
> Please advice.
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> 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.
>
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list