[R] How to convert a frame to a matrix while maintaining that a number is still a number?
Peng Yu
pengyu.ut at gmail.com
Thu Sep 17 00:12:35 CEST 2009
Hi,
See the code below.
'x' is a frame. x$C1 are all numbers 1, 2 and 3.
'as.matrix(x)' convert x$C1 to strings "1", "2" and "3". I'm wondering
how to maintain that the first column of 'as.matrix(x)' still numbers.
Regards,
Peng
$ cat read.csv
"C1","C2"
"1","x"
"2","y"
"3","z"
$ Rscript read.csv.R
> x=read.csv("read.csv")
> str(x)
'data.frame': 3 obs. of 2 variables:
$ C1: int 1 2 3
$ C2: Factor w/ 3 levels "x","y","z": 1 2 3
> as.matrix(x)
C1 C2
[1,] "1" "x"
[2,] "2" "y"
[3,] "3" "z"
>
More information about the R-help
mailing list