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 answer, but was
wondering if there are obvious
I don't know if this is better, but it's the most obvious/shortest I
could come up with. Transpose the data.frame column to a 'row' vector
and drop the dimensions.
R identical(nv, drop(t(df)))
[1] TRUE
Best,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
On
Hello,
A bit more general
nv - c(a=1, d=17, e=101); nv
nv2 - c(a=a, d=d, e=e)
df2 - data.frame(VAR = nv, CHAR = nv2); df2
identical( nv, drop(t( df2[1] )) ) # TRUE
identical( nv, drop(t( df2[[1]] )) ) # FALSE
Rui Barradas
Em 18-08-2012 16:16, Joshua Ulrich escreveu:
I don't know if this
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:
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,
?mccollect say
'mccollect' returns any results that are available in a list. The
results will have the same order as the specified jobs. If there
are multiple jobs and a job has a name it will be used to name the
result, otherwise its process ID will be used. If none of
Joshua Ulrich josh.m.ulr...@gmail.com
on Sat, 18 Aug 2012 10:16:09 -0500 writes:
I don't know if this is better, but it's the most obvious/shortest I
could come up with. Transpose the data.frame column to a 'row' vector
and drop the dimensions.
R identical(nv,
On Sat, Aug 18, 2012 at 9:33 AM, Martin Maechler
maech...@stat.math.ethz.ch wrote:
Joshua Ulrich josh.m.ulr...@gmail.com
on Sat, 18 Aug 2012 10:16:09 -0500 writes:
I don't know if this is better, but it's the most obvious/shortest I
could come up with. Transpose the data.frame
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:
Consider this toy example, where the dataframe already has only
one column :
This isn't super-concise, but has the virtue of being clear:
nv - c(a=1, d=17, e=101)
df - as.data.frame(cbind(VAR = nv))
identical(nv, setNames(df$VAR, rownames(df)))
# TRUE
It seems to be more efficient than the other methods as well:
f1 - function() setNames(df$VAR, rownames(df))
f2 -
On Sat, Aug 18, 2012 at 10:03 AM, Martin Maechler
maech...@stat.math.ethz.ch 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
That would have been essentially my suggestion as well. I prefer its clarity
(and speed). I didn't know if you wanted your solution to also apply
to matrices embedded in data.frames. In S+ rownames-() works on vectors
(because it calls the generic rowId-()) so the following works:
f4 -
11 matches
Mail list logo