You can't do this using matrix class, matrix convert all values to same class, in this case, character.
On Wed, Sep 16, 2009 at 7:12 PM, Peng Yu <pengyu...@gmail.com> wrote: > 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" >> > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.