[R] extract element from list by rownames

From: Alfredo Alessandrini <alfreale74_at_gmail.com>
Date: Tue, 12 Apr 2011 16:16:24 +0200


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. Received on Tue 12 Apr 2011 - 14:21:04 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 Tue 12 Apr 2011 - 15:40:29 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