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
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
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
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
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
5 matches
Mail list logo