[R] data.frame into vector

Tiago R Magalhaes tiago17 at socrates.Berkeley.EDU
Tue Nov 23 17:27:03 CET 2004


I want to extract a row from a data.frame but I want that object to 
be a vector . After trying some different ways I end up always with a 
data.frame or with the wrong vector. Any pointers?

  x <- data.frame(a = factor(c('a',2,'b')), b = c(4,5,6))
I want to get
"a" "4"

I tried:

   a b
1 a 4
(resulting in a data.frame even after in my mind having coerced it 
into a vector!)

as.vector(c[1,], numeric='character')
[1] "2" "4"
(almost what I want, except that "2" instead of "a" - I guess this as 
to do with levels and factors)

Thanks for any help

>  R.Version()
[1] "powerpc-apple-darwin6.8"

[1] "powerpc"

[1] "darwin6.8"

[1] "powerpc, darwin6.8"

[1] ""

[1] "2"

[1] "0.1"

[1] "2004"

[1] "11"

[1] "15"

[1] "R"

More information about the R-help mailing list