[R] extracting rows of a dataframe

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Fri 02 Dec 2005 - 19:50:19 EST


Hi

look at the following session, in which I have a dataframe, and I want to extract the second row, without the first column.

Everything works as expected until the last line, where I set the names of x to NULL, and get a non-desired object (I want c(4,3).).

Three questions:

(1) why is as.vector(a[2,-1]) not a vector?

(2) How come setting names to NULL gives me bad weirdness?

(3) Can I structure my dataframe in a better way, so that this problem does not occur?

> a <- data.frame(male=c(T,T,F),mass=c(1,4,3),height=c(4,3,2))
> a

    male mass height

1  TRUE    1      4
2  TRUE    4      3
3 FALSE    3      2

> x <- as.vector(a[2,-1])
> x


   mass height
2 4 3
> names(x) <- NULL
> x

   structure("4", class = "AsIs") structure("3", class = "AsIs")
2                              4                              3

>
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Dec 02 20:05:50 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:28 EST