Hello! I am a beginner to R. I have read several guides, but still am stuck on this: I have data in an excel csv file, on which I want to run PCA. I'm not sure how the prcomp formula works. The help page states: prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE, tol = NULL, ...) what is x referring to? I tried putting the file name for x, but i get the following error: Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric what kind of numeric value do I need to put in for x? Potentially helpful information: my data sheet has around 48 columns and over 7000 rows. I have converted the csv file into a matrix in R. Thanks in advance for all your help. I'd appreciate step by step instructions on how to go from my csv file to a PCA biplot in R. [[alternative HTML version deleted]]
I'd you keep reading the help file, the answer to your question is right there. As for step by step... only you know what your data looks like. There are various pitfalls one can encounter in getting data from a file into an object in memory, but the basic idea is to use the read.csv function, and then optionally the str function to verify that it has been read in properly. There is a whole document that comes with R to show you how to get data into and out of R, and a reproducible example is needed if we are to be able to give specific guidance. [1] Oh and there is a Posting Guide that you should read mentioned at the bottom if this and every message on the list. Among the valuable nuggets in there is a statement that this is a plain text mailing list (HTML email gets stripped to text do we don't necessarily see what you see), so please send plain text only so you know what we will see. [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On January 13, 2015 3:17:11 PM PST, R Help! <emanekaf5 at gmail.com> wrote:>Hello! > >I am a beginner to R. I have read several guides, but still am stuck on >this: > >I have data in an excel csv file, on which I want to run PCA. >I'm not sure how the prcomp formula works. The help page states: >prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE, >tol = NULL, ...) > >what is x referring to? I tried putting the file name for x, but i get >the >following error: >Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric > >what kind of numeric value do I need to put in for x? > >Potentially helpful information: my data sheet has around 48 columns >and >over 7000 rows. I have converted the csv file into a matrix in R. > >Thanks in advance for all your help. > >I'd appreciate step by step instructions on how to go from my csv file >to a >PCA biplot in R. > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.
Hi error message indicates that you have non numeric value in your table/ matrix. Replace missing value by NA and add na.rm= true in your command prcomp. Karim Le 14 janv. 2015 00:27, "R Help!" <emanekaf5 at gmail.com> a ?crit :> Hello! > > I am a beginner to R. I have read several guides, but still am stuck on > this: > > I have data in an excel csv file, on which I want to run PCA. > I'm not sure how the prcomp formula works. The help page states: > prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE, > tol = NULL, ...) > > what is x referring to? I tried putting the file name for x, but i get the > following error: > Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric > > what kind of numeric value do I need to put in for x? > > Potentially helpful information: my data sheet has around 48 columns and > over 7000 rows. I have converted the csv file into a matrix in R. > > Thanks in advance for all your help. > > I'd appreciate step by step instructions on how to go from my csv file to a > PCA biplot in R. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >[[alternative HTML version deleted]]
Brandstätter Christian
2015-Jan-14 08:41 UTC
[R] Help on Principal Component Analysis in R
Hi, it could also be that during reading your csv the matrix became a character matrix. Try str(x); this should show you if your values are seen as numeric. Also, if you have descriptive columns (e.g. date, labels, etc.) they must be removed before calculating PCR. With best regards Brandst?tter Christian 2015-01-14 0:17 GMT+01:00 R Help! <emanekaf5 at gmail.com>:> Hello! > > I am a beginner to R. I have read several guides, but still am stuck on > this: > > I have data in an excel csv file, on which I want to run PCA. > I'm not sure how the prcomp formula works. The help page states: > prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE, > tol = NULL, ...) > > what is x referring to? I tried putting the file name for x, but i get the > following error: > Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric > > what kind of numeric value do I need to put in for x? > > Potentially helpful information: my data sheet has around 48 columns and > over 7000 rows. I have converted the csv file into a matrix in R. > > Thanks in advance for all your help. > > I'd appreciate step by step instructions on how to go from my csv file to a > PCA biplot in R. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >[[alternative HTML version deleted]]