Skip to content
Back to formatted view

Raw Message

Message-ID: <89b6b8c90809112235w30c17301o58ab9a6f5fa2847e@mail.gmail.com>
Date: 2008-09-12T05:35:37Z
From: Yihui Xie
Subject: Save object summary to file
In-Reply-To: <19447000.post@talk.nabble.com>

Hi,

The returned value of summary.princomp() is NOT a data.frame and
cannot be coerced into a data.frame (it's a list), so you cannot write
it into a file using write.table().

I guess what you really intend to write is:

#################################################################
x <- summary(PCA)
vars <- x$sdev^2
vars <- vars/sum(vars)
write.table(rbind("Standard deviation" = x$sdev, "Proportion of
Variance" = vars,
        "Cumulative Proportion" = cumsum(vars), file="PCAvar.txt", sep="\t")
#################################################################

Yihui

On Fri, Sep 12, 2008 at 7:51 AM, pgseye <prseye at gmail.com> wrote:
>
> Hi,
>
> Am wanting to save the summary of a PCA to file.
>
> Have tried:
>
>> write.table(summary(PCA), file="PCAvar.txt", sep="\t")
>
> but receive:
>
> Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors =
> stringsAsFactors) :
>  cannot coerce class "summary.princomp" into a data.frame
>
> What am I doing wrong?
>
> Thanks
>
>


-- 
Yihui Xie <xieyihui at gmail.com>
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China