[R] list index rules evaluation behavior

David Winsemius dwinsemius at comcast.net
Tue Mar 30 21:38:23 CEST 2010


On Mar 30, 2010, at 1:41 PM, Dgnn wrote:

>
> Sorry for not supplying some example code for the above example.  
> Here's an
> example list 'a' with histogram elements A, B, and C which are also  
> lists.

That is not code. That is output. It is not clear how "a" was created
>
>> a
>
> $A
> $breaks

If you want to access the breaks element then try any of these  
untested guesses:

a$A$breaks

or:

a["A"][["breaks"]]

a$A["breaks"]

With the example on the help page for hist() you would get:

 > a <- hist(islands)
 > a["breaks"]
$breaks
  [1]     0  2000  4000  6000  8000 10000 12000 14000 16000 18000

 > a[["breaks"]]
  [1]     0  2000  4000  6000  8000 10000 12000 14000 16000 18000


> [1] -80 -70 -60 -50 -40 -30 -20 -10   0  10  20  30  40  50  60
> $counts
> [1]   1   0   0   2  29 120 301 433 421 265  93  43   9   3
> $intensities
> [1] 5.81e-05 0.000000e+00 0.000000e+00 1.162791e-04 1.686047e-03
> 6.976744e-03 1.750000e-02
> [8] 2.512e-02 2.447674e-02 1.540698e-02 5.406977e-03 2.500000e-03
> 5.232558e-04 1.744186e-04
>
> $density
> [1] 5.813-05 0.000000e+00 0.000000e+00 1.162791e-04 1.686047e-03
> 6.976744e-03 1.750000e-02
> [8] 2.517442e-02 2.447674e-02 1.540698e-02 5.406977e-03 2.500000e-03
> 5.232558e-04 1.744186e-04
>
> $mids
> [1] -75 -65 -55 -45 -35 -25 -15  -5   5  15  25  35  45  55
>
> $xname
> [1] "X[[1L]]"
>
> $equidist
> [1] TRUE
>
> attr(,"class")
> [1] "histogram"
>
> $B
> $breaks
> [1] -40 -35 -30 -25 -20 -15 -10  -5   0   5  10  15  20  25  30  35
> $counts
> [1]   2   1   3  20  86 225 396 408 404 294 182 125  38  11   1
> ...
> $C
> ...
>
> Is there a way to index the $xname element from each of the elements  
> of a?
> -- 
> View this message in context: http://n4.nabble.com/list-index-rules-evaluation-behavior-tp1745398p1745579.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list