[R] Why doesn't as.vector() return a vector?

Peter Kleiweg kleiweg at let.rug.nl
Fri Jan 5 18:45:57 CET 2001


I use as.vector() on a data frame and I get a data frame in
return. No warning. I have to use as.matrix() first. Why is
that? Doesn't make sense to me. I'm using R 1.2.0 on Linux.

    > F <- data.frame(a = c(1,2,3), b = c(4,5,6))
    > F
      a b
    1 1 4
    2 2 5
    3 3 6
    > V <- as.vector(F)
    > V
      a b
    1 1 4
    2 2 5
    3 3 6
    > attributes(V)
    $names
    [1] "a" "b"
    
    $row.names
    [1] "1" "2" "3"
    
    $class
    [1] "data.frame"
    
    > as.vector(as.matrix(F))
    [1] 1 2 3 4 5 6 

-- 
Peter Kleiweg
http://www.let.rug.nl/~kleiweg/

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list