[R] Extracting columns from a class

Thomas Levine thomas.levine at gmail.com
Sat Mar 19 15:13:38 CET 2011


Hi,

Here is the prcomp output.

tom=prcomp(matrix(rnorm(25),5,5))

R functions often output lists. To see what's in this one, run
"names(tom)" or type "tom$" and use tab completion. Once you do that,
the following is more obvious.

pc1=tom$rotation[,1]
sd1=tom$sdev[1]
column=c(sd1,pc1)

write.table(column,"tom",row.names=F,col.names=F)

This will send the column to the file "tom".

Tom

On Thu, Mar 17, 2011 at 8:10 AM, nuncio m <nuncio.m at gmail.com> wrote:
> Hi list,
>           I am not a frequent user of R.  Recently I used R in principal
> component analysis and got the result as a class, which has information like
> standard deviation and principal components from 1 to 10.  How is it
> possible to extract the column corresponding to first principal component
> and write it to a file
> the out from prcomp command is something like this
>
> Standard
> deviations:
>
>  [1] 3.325801e+00 7.669837e-01 6.625773e-01 4.990732e-01 3.470071e-01
>  [6] 2.946679e-01 2.206289e-01 1.645828e-01 1.570887e-01
> 4.741294e-16
>
>
> Rotation:
>               PC1           PC2           PC3           PC4          PC5
>  [1,] -0.07900624 -0.0824864352  0.1208419434  0.1763425845  0.089545020
>  [2,] -0.09114708 -0.0901675110  0.1377608881  0.2224127252  0.076620976
>  [3,] -0.10510742 -0.0935434206  0.1113586044  0.2513993555  0.029783117
>
> I want to extract PC1 and 1 value in the standard deviation
>
> Thanks
>
> --
> Nuncio.M
> Research Scientist
> National Center for Antarctic and Ocean research
> Head land Sada
> Vasco da Gamma
> Goa-403804
>
>        [[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