Skip to content
Prev 82012 / 398503 Next

extracting rows of a dataframe

RH> Three questions:

    RH> (1)  why is as.vector(a[2,-1]) not a vector?
Did you read the help file of as.vector() ?
male mass height
1  TRUE    1      4
2  TRUE    4      3
3 FALSE    3      2
[1] "list"
`data.frame':	1 obs. of  2 variables:
 $ mass  : num 4
 $ height: num 3

Clearly you want:
num [1:2] 4 3
[1] 4 3


    RH> (2) How come setting names to NULL gives me bad weirdness?
`data.frame':	1 obs. of  2 variables:
 $ : num 4
 $ : num 3
structure("4", class = "AsIs") structure("3", class = "AsIs")
2                              4                              3

With your "names(x)<-NULL" command you are wiping out the names of the
variables in your data frame.  Looking at print.data.frame(), the
answer to the so-called weirdness can presumably be found in
format.data.frame(). 

    RH> (3) Can I structure my dataframe in a better way, so that
    RH> this problem does not occur?
Not really, it's more a question of the appropriate use of
as.vector(). :-))

Cheers,

        Berwin

========================== Full address ============================
Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)   
School of Mathematics and Statistics        +61 (8) 6488 3383 (self)      
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway                   
Crawley WA 6009                e-mail: berwin at maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin