[R] Storing CA Results to a Data Frame?

Ista Zahn izahn at psych.rochester.edu
Sun Sep 26 21:10:25 CEST 2010


Hi Vik,
I suggest reading through some of the introductory documentation. R
has several classes of objects, including matrix, list, data.frame
etc. and a basic understanding of what these are is essential for
effectively using R. An essential function is str() which shows you
the structure of an object. Other essential functions include names(),
help(), help.search(), and methods()

An example session that is similar to your case:

library(ca) # load the ca package
data(author) # load the authors dataset
str(author) # examine the authors data
auth.ca <- ca(author) # run the ca function on the authors data
str(auth.ca) # examin the structure of the auth.ca results. Note that
it is a list with class of "ca"
methods(class=class(auth.ca)) # see what methods are defined for this
type of object
?plot.ca ## look up the documentation for the plot method for objects
of class "ca"
plot(auth.ca) ## call the plot method
auth.ca.sum <- summary(auth.ca) ## call the summary method
str(auth.ca.sum) # examine the structure of the auth.ca.sum object
methods(class=class(auth.ca.sum)) ## find out what methods are defined for it
## Hmmn ok, so suppose I want to extract the "rows" and "columns"
data.frames from auth.ca.sum but don't know how
help.search("extract") ## first result is base::Extract
?Extract ## look up documentation for extract
auth.ca.rows <- auth.ca.sum[["rows"]] ## extract the "rows" data.frame
auth.ca.rows <- auth.ca.sum[["columns"]] ## extract the "columns" data.frame
write.csv(auth.ca.rows) ## write results to a .csv file
write.csv(auth.ca.rows) ## ""

HTH,
Ista

On Sun, Sep 26, 2010 at 6:10 PM, Vik Rubenfeld <vikr at mindspring.com> wrote:,
> I am successfully performing a correspondence analysis using the commands:
>
>        NonLuxury <- read.table("/Users/myUserName/Desktop/nonLuxury.data.txt")
>        ca(NonLuxury)
>
> I would like to store the results to a data frame so that I can write them to disk using write.table.  I have tried several things such as:
>
>        df <- data.frame(ca(NonLuxury))
>        df <- data.frame(data(ca(NonLuxury)))
>        etc.
>
> ...but clearly this is incorrect as it generates an error message.
>
> Is it possible to store the results of a CA to a dataframe, and if so, what is the correct way to do this?
>
> Thanks in advance to all for any info.
>
>
> -Vik
> ______________________________________________
> 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list