Re: [R] extracting named vector from dataframe

2010-10-31 Thread Gabor Grothendieck
On Sun, Oct 31, 2010 at 12:11 PM, baptiste auguie wrote: > Hi, > > I think you want ?unlist > > d = data.frame(x=1, y=2, z=3) > v = unlist(d) > is(v) > [1] "numeric" "vector" > Here are a few other possibilities too: drop(as.matrix(d)) do.call("c", d) sapply(d, identity) -- Statisti

Re: [R] extracting named vector from dataframe

2010-10-31 Thread James Hirschorn
tions such as sort(). -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Sunday, October 31, 2010 12:24 PM To: James Hirschorn Cc: R-help@r-project.org Subject: Re: [R] extracting named vector from dataframe On Oct 31, 2010, at 11:54 AM, James Hirschorn

Re: [R] extracting named vector from dataframe

2010-10-31 Thread David Winsemius
On Oct 31, 2010, at 11:54 AM, James Hirschorn wrote: Suppose df is a dataframe with one named row of numeric observations. I want to coerce df into a named vector. I don't think you understand the structure of dataframes. They are named lists of component columns. The names you are attrib

Re: [R] extracting named vector from dataframe

2010-10-31 Thread baptiste auguie
Hi, I think you want ?unlist d = data.frame(x=1, y=2, z=3) v = unlist(d) is(v) [1] "numeric" "vector" HTH, baptiste On 31 October 2010 16:54, James Hirschorn wrote: > Suppose df is a dataframe with one named row of numeric observations. I want > to coerce df into a named vector. > > > > as.ve

[R] extracting named vector from dataframe

2010-10-31 Thread James Hirschorn
Suppose df is a dataframe with one named row of numeric observations. I want to coerce df into a named vector. as.vector does not work as I expected: as.vector(df) returns the original dataframe, while as.vector(df,mode="numeric") returns an unnamed vector of NAs. This works: > v <- as