[R] extracting rows of a dataframe
Robin Hankin
r.hankin at noc.soton.ac.uk
Fri Dec 2 09:50:19 CET 2005
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
More information about the R-help
mailing list