[R] how to extract from list

arun smartpink111 at yahoo.com
Tue Oct 16 14:10:49 CEST 2012


HI,
Try this:
To extract kappa:
list1<-list(X199997=data.frame(xi=784.77,alpha=165.406,kappa=-0.2709),X19998=data.frame(xi=860.783,alpha=215.114,kappa=-0.1769))
sapply(list1,`[`,3)
#$X199997.kappa
#[1] -0.2709

#$X19998.kappa
[1] -0.1769

#To extract alpha:
 sapply(list1,`[`,2)
#$X199997.alpha
#[1] 165.406

#$X19998.alpha
#[1] 215.114

#To extract xi:
sapply(list1,`[`,1) 

A.K>




----- Original Message -----
From: Balqis <aehan3616 at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, October 16, 2012 7:17 AM
Subject: [R] how to extract from list

Hi all,

I have a list of 20000 data, and the list look like below. I wonder what is
the simplest way to extract 'kappa' value (or 'xi' or 'alpha' for the
matter)  from each of the data. How can I simply code it without having to
change the list to a dataframe first? Many thanks!


$X19997
         xi       alpha       kappa
784.7718640 165.4065141  -0.2709599

$X19998
         xi       alpha       kappa
860.7832604 215.1144980  -0.1769741

$X19999
         xi       alpha       kappa
839.7692675 196.0103874  -0.3848809

$X20000
         xi       alpha       kappa
847.6117040 212.3279185  -0.2576029

regards,
aehan

    [[alternative HTML version deleted]]

______________________________________________
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.





More information about the R-help mailing list