silly question about read.table
2
0
Entering edit mode
@james-anderson-1641
Last seen 9.7 years ago
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/bioconductor/attachments/20070224/ ed9d4cc4/attachment.pl
• 449 views
ADD COMMENT
0
Entering edit mode
@sean-davis-490
Last seen 4 months ago
United States
James Anderson wrote: > I am trying to use pamr (prediction analysis of microarray), which uses nearest shrunken centroid classification. Now I want to load my data using read.table, then use pamr. the codes are as follows: > > Training = read.table("A.txt",header = FALSE) > myData = list(x = Training,y = factor(TrainingLabel)); > mytrain = pamr.train(myData) > It always complains "Error in x %*% Y : requires numeric matrix/vector arguments" > > I think the main reason is variable Training read from read.table is an object, not just numeric matrix, I tried as.numeric(Training), it still has errors. I know if Training is created by something like > > Training = matrix(rnorm(1000*20),ncol=20) > It will not complain, since by this way, Training is purely a numeric matrix, not object. Does anybody know how to convert the object read from read.table to a pure numeric matrix? > Hi, James. If A.txt has any text columns in it, you will want to remove those before reading it into R (or after it is in R). Then, you should be able to do: Training.matrix = as.matrix(Training) Does that do what you want? Sean
ADD COMMENT
0
Entering edit mode
@jdelasherasedacuk-1189
Last seen 8.8 years ago
United Kingdom
Quoting James Anderson <janderson_net at="" yahoo.com="">: > I am trying to use pamr (prediction analysis of microarray), which > uses nearest shrunken centroid classification. Now I want to load my > data using read.table, then use pamr. the codes are as follows: > > Training = read.table("A.txt",header = FALSE) > myData = list(x = Training,y = factor(TrainingLabel)); > mytrain = pamr.train(myData) > It always complains "Error in x %*% Y : requires numeric > matrix/vector arguments" > > I think the main reason is variable Training read from read.table is > an object, not just numeric matrix, I tried as.numeric(Training), > it still has errors. I know if Training is created by something like > > Training = matrix(rnorm(1000*20),ncol=20) > It will not complain, since by this way, Training is purely a > numeric matrix, not object. Does anybody know how to convert the > object read from read.table to a pure numeric matrix? > > Thanks, > > James I am not familiar with pamr and the arguments it requires, but read.table will create a data frame object. As it has no header and (presumably) it only contains numbers in a table form, if you use 'as.matrix(Training)' you'll convert Training from a data frame to a numeric matrix. If pamr expects a list where the first element is a matrix, it may work. Anyway, use 'as.matrix', not 'as.numeric' I hope this helps a bit! Jose -- Dr. Jose I. de las Heras Email: J.delasHeras at ed.ac.uk The Wellcome Trust Centre for Cell Biology Phone: +44 (0)131 6513374 Institute for Cell & Molecular Biology Fax: +44 (0)131 6507360 Swann Building, Mayfield Road University of Edinburgh Edinburgh EH9 3JR UK
ADD COMMENT
0
Entering edit mode
If you look at the documentation for read.table, you will see a variable " colClasses". You can use this to set each column to the correct type. --Naomi At 09:34 PM 2/24/2007, J.delasHeras at ed.ac.uk wrote: >Quoting James Anderson <janderson_net at="" yahoo.com="">: > > > I am trying to use pamr (prediction analysis of microarray), which > > uses nearest shrunken centroid classification. Now I want to load my > > data using read.table, then use pamr. the codes are as follows: > > > > Training = read.table("A.txt",header = FALSE) > > myData = list(x = Training,y = factor(TrainingLabel)); > > mytrain = pamr.train(myData) > > It always complains "Error in x %*% Y : requires numeric > > matrix/vector arguments" > > > > I think the main reason is variable Training read from read.table is > > an object, not just numeric matrix, I tried as.numeric(Training), > > it still has errors. I know if Training is created by something like > > > > Training = matrix(rnorm(1000*20),ncol=20) > > It will not complain, since by this way, Training is purely a > > numeric matrix, not object. Does anybody know how to convert the > > object read from read.table to a pure numeric matrix? > > > > Thanks, > > > > James > >I am not familiar with pamr and the arguments it requires, but >read.table will create a data frame object. As it has no header and >(presumably) it only contains numbers in a table form, if you use >'as.matrix(Training)' you'll convert Training from a data frame to a >numeric matrix. If pamr expects a list where the first element is a >matrix, it may work. Anyway, use 'as.matrix', not 'as.numeric' > >I hope this helps a bit! > >Jose > >-- >Dr. Jose I. de las Heras Email: J.delasHeras at ed.ac.uk >The Wellcome Trust Centre for Cell Biology Phone: +44 (0)131 6513374 >Institute for Cell & Molecular Biology Fax: +44 (0)131 6507360 >Swann Building, Mayfield Road >University of Edinburgh >Edinburgh EH9 3JR >UK > >_______________________________________________ >Bioconductor mailing list >Bioconductor at stat.math.ethz.ch >https://stat.ethz.ch/mailman/listinfo/bioconductor >Search the archives: >http://news.gmane.org/gmane.science.biology.informatics.conductor Naomi S. Altman 814-865-3791 (voice) Associate Professor Dept. of Statistics 814-863-7114 (fax) Penn State University 814-865-1348 (Statistics) University Park, PA 16802-2111
ADD REPLY

Login before adding your answer.

Traffic: 568 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6