Skip to content

how can I convert .csv format to matrix???

4 messages · bbslover, Steven Kang, Dieter Menne

#
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!
#
bbslover wrote:
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
1 day later
#
thank you for your help,it is a good way.
Steven Kang wrote: