Re: [R] How to access data structure (List of List)

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Mon, 23 Jun 2008 09:34:05 +0200

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

______________________________________________
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.
Received on Mon 23 Jun 2008 - 07:38:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 08:31:01 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive