[R] data.frame to character

Muhammad Subianto subianto at gmail.com
Fri Jun 10 14:23:52 CEST 2005


Hi,
Excuse me for this simple question.
How to convert as.data.frame to as.character?

  ?data.frame

 > L3 <- LETTERS[1:3]
 >  L10 <- LETTERS[1:10]
 >  d <- data.frame(cbind(x=c("XYZ"), y=L10), fac=sample(L3, 10, repl=TRUE))
 >  d
      x y fac
1  XYZ A   A
2  XYZ B   A
3  XYZ C   A
4  XYZ D   A
5  XYZ E   B
6  XYZ F   C
7  XYZ G   A
8  XYZ H   C
9  XYZ I   B
10 XYZ J   A
 >  str(d)
`data.frame':   10 obs. of  3 variables:
  $ x  : Factor w/ 1 level "XYZ": 1 1 1 1 1 1 1 1 1 1
  $ y  : Factor w/ 10 levels "A","B","C","D",..: 1 2 3 4 5 6 7 8 9 10
  $ fac: Factor w/ 3 levels "A","B","C": 1 1 1 1 2 3 1 3 2 1
 >  d[3,]
     x y fac
3 XYZ C   A
 >
 >  as.character(d[3,])
[1] "1" "3" "1"
 >

I think as.character the result something like
[3] "XYZ" "C" "A"

I don't know how to convert it.
Any help gratefully received.
Thank you very much in advance.
Kindly regards,
Muhammad Subianto




More information about the R-help mailing list