Re: [Rd] Quiz: How to get a named column from a data frame

2012-08-19 Thread Bert Gunter
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 ruipbarra...@sapo.pt wrote: Hello, A bit more general nv - c(a=1,

Re: [Rd] Quiz: How to get a named column from a data frame

2012-08-19 Thread Bert Gunter
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 g 7 G

Re: [Rd] Quiz: How to get a named column from a data frame

2012-08-19 Thread Bert Gunter
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 bgun...@gene.com 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

Re: [Rd] Quiz: How to get a named column from a data frame

2012-08-19 Thread J. R. M. Hosking
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

Re: [Rd] Quiz: How to get a named column from a data frame

2012-08-19 Thread Andrew Piskorski
On Sat, Aug 18, 2012 at 02:13:20PM -0400, Christian Brechb?hler wrote: On 8/18/12, Martin Maechler maech...@stat.math.ethz.ch 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 maech...@stat.math.ethz.ch wrote: