In my disk C:/ have a a.csv file, I want to read it to R, importantly, when I use x=read.csv("C:/a.csv") ,the x format is data.frame, I want to it to become matrix format, how can I do it ? thank you! -- View this message in context: http://old.nabble.com/how-can-I-convert-.csv-format-to-matrix----tp26156643p26156643.html Sent from the R help mailing list archive at Nabble.com.
can try matrix.x <- as.matrix(x) On Mon, Nov 2, 2009 at 8:38 PM, bbslover <dluthm@yeah.net> wrote:> > In my disk C:/ have a a.csv file, I want to read it to R, importantly, > when > I use x=read.csv("C:/a.csv") ,the x format is data.frame, I want to it > to > become matrix format, how can I do it ? > > thank you! > -- > View this message in context: > http://old.nabble.com/how-can-I-convert-.csv-format-to-matrix----tp26156643p26156643.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
bbslover wrote:> > In my disk C:/ have a a.csv file, I want to read it to R, importantly, > when I use x=read.csv("C:/a.csv") ,the x format is data.frame, I want > to it to become matrix format, how can I do it ? >as.matrix should do the job; if it does not (second example), you probably have rownames or some other string in your data set. Dieter # use read.csv instead x = data.frame(a=1:10,b=11:20) xm = as.matrix(x) str(xm) xm # looks good x1 = data.frame(a=1:10,b=11:20,c=letters[1:10]) xm1 = as.matrix(x1) str(xm1) xm1 # looks strange, because it's all strings -- View this message in context: http://old.nabble.com/how-can-I-convert-.csv-format-to-matrix----tp26156643p26157732.html Sent from the R help mailing list archive at Nabble.com.
thank you for your help,it is a good way. Steven Kang wrote:> > can try > > matrix.x <- as.matrix(x) > > On Mon, Nov 2, 2009 at 8:38 PM, bbslover <dluthm at yeah.net> wrote: > >> >> In my disk C:/ have a a.csv file, I want to read it to R, importantly, >> when >> I use x=read.csv("C:/a.csv") ,the x format is data.frame, I want to it >> to >> become matrix format, how can I do it ? >> >> thank you! >> -- >> View this message in context: >> http://old.nabble.com/how-can-I-convert-.csv-format-to-matrix----tp26156643p26156643.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> 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<http://www.r-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> > > [[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. > >-- View this message in context: http://old.nabble.com/how-can-I-convert-.csv-format-to-matrix----tp26156643p26191114.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- how can I plot the histogram like this using R?
- Help,Suggest me some methods to identify training set and test set!!!
- how to replace my double for loop which is little efficient!
- variable selectin---reduce the numbers of initial variable
- Please help me!!!! Error in `[.data.frame`(x, , retained, drop = FALSE) : undefined columns selected