Skip to content
Prev 8763 / 398502 Next

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

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