I have some output from a tapply call that looks like
1 2 4
678.2 19.3 716.2
and I want to make it into a data frame that looks like
key value
1 1 678.2
2 2 19.3
3 4 716.2
how can I do this?
If you replace tapply
with aggregate it will automatically come out as a data.frame.
aggregate( value ~ key, FUN = mean )
where value and key correspond to the tapply
call
tapply( value, key, mean )
Some example code would be nice, to see exactly what you're doing. To answer your question narrowly, if x
is the result of your tapply
, then
data.frame(key=names(x), value=x)
More broadly, see ?by
and ?aggregate
, and also package plyr
for more general data-wrangling needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With