[R] Pulling out parts of a generated array in R

Uwe Ligges ligges at statistik.uni-dortmund.de
Sat Sep 15 18:28:34 CEST 2007



Wayne Aldo Gavioli wrote:
> Hello all,
> 
> I was wondering if it was possible to pull out certain parts of an array in R -
> not an array of data that I have created, but an array of data that has been
> spit out by R itself.
> 
> More specifically, in the lines of code below:
> 
> 
>> summary(prcomp(USArrests))
> Importance of components:
>                           PC1     PC2    PC3     PC4
> Standard deviation     83.732 14.2124 6.4894 2.48279
> Proportion of Variance  0.966  0.0278 0.0058 0.00085
> Cumulative Proportion   0.966  0.9933 0.9991 1.00000
> 
> 
> 
> I was wondering if there is a way to only extract one piece of this array,
> specifically the Proportion of Variance for PC2, which is 0.0278.  I know how
> to extract one entire line of data from this array, using the following lines
> of code:
> 
>> result<-summary(prcomp(USArrests))
>> m<-result$importance
>> final<-m[2,]
> 
> 
> These lines of code will produce the follwing output:
> 
> 
> 0.966  0.0278 0.0058 0.00085
>
> 
> Now I was wondering if there is anyway to break this down even further, and be
> able to extract one piece of data from this one line.

I am sure you already read about matrix indexing in the manual "An 
Introduction to R", but here to remind you how easy it is to get the 
second row, third column:

final <- m[2,3]

Uwe Ligges


> 
> If anyone could help me out, I would really appreciate it.
> 
> 
> Thanks,
> 
> 
> Wayne
> 
> ______________________________________________
> 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