[R] acast: how to obtain names?

Marius Hofert marius.hofert at math.ethz.ch
Fri Nov 18 10:19:25 CET 2011


Hi,

After applying acast() I typically have to adjust the names of the array by hand. Is there any way to tell acast to do this automatically?

Cheers,

Marius

require(reshape2)
(df <- data.frame(a=c("a1","a2"), b=c("b1","b2"), c=c("c1","c2")))
a.df <- acast(df, a~b, value_var="c")
names(dimnames(a.df)) # => NULL; would be nice to get the following:
names(dimnames(a.df)) <- c("a", "b")
a.df



More information about the R-help mailing list