Yes, but either
drop(t(df[,1,drop=TRUE]))
or
t(df[,1,drop=TRUE])[1,]
does work. My minimal effort to check timings found that the first
version was a hair faster.
-- Bert
On Sat, Aug 18, 2012 at 9:01 AM, Rui Barradas wrote:
> Hello,
>
> A bit more general
>
> nv <- c(a=1, d=17, e=101); nv
>
Or to expand just a hair on Joshua's suggestion, is the following what you want:
> x <- 1:10
> names(x) <- letters[1:10]
> x
a b c d e f g h i j
1 2 3 4 5 6 7 8 9 10
> df <- data.frame(x=x,y=LETTERS[1:10],row.names=names(x))
> df
x y
a 1 A
b 2 B
c 3 C
d 4 D
e 5 E
f 6 F
Sorry! -- Change that to drop = FALSE !
drop(t(df[,1,drop=FALSE]))
t(df[,1,drop=FALSE])[1,]
-- Bert
On Sat, Aug 18, 2012 at 9:37 AM, Bert Gunter wrote:
> Yes, but either
>
> drop(t(df[,1,drop=TRUE]))
>
> or
>
> t(df[,1,drop=TRUE])[1,]
>
> does work. My minimal effort to check timings found t
On 2012-08-18 11:03, Martin Maechler wrote:
Today, I was looking for an elegant (and efficient) way
to get a named (atomic) vector by selecting one column of a data frame.
Of course, the vector names must be the rownames of the data frame.
Ok, here is the quiz, I know one quite "cute"/"slick" an
On Sat, Aug 18, 2012 at 02:13:20PM -0400, Christian Brechb?hler wrote:
> On 8/18/12, Martin Maechler wrote:
> > On Sat, Aug 18, 2012 at 5:14 PM, Christian Brechb?hler wrote:
> >> On Sat, Aug 18, 2012 at 11:03 AM, Martin Maechler
> >> wrote:
>
> >>> Consider this toy example, where the dataf