[R] tapply output as a dataframe
Dan Dube
ddube at advisen.com
Mon Apr 13 20:22:33 CEST 2009
this is what i needed! thank you.
> -----Original Message-----
> From: Jorge Ivan Velez [mailto:jorgeivanvelez at gmail.com]
> Sent: Monday, April 13, 2009 12:50 PM
> To: Dan Dube
> Cc: r-help at r-project.org
> Subject: Re: [R] tapply output as a dataframe
>
>
> Dear Dan,
>
> Try this:
>
> do.call(rbind,a)
>
>
> HTH,
>
> Jorge
>
>
>
> On Mon, Apr 13, 2009 at 12:41 PM, Dan Dube <ddube at advisen.com> wrote:
>
>
> i use tapply and by often, but i always end up banging
> my head against
> the wall with the output.
>
> is there a simpler way to convert the output of the
> following tapply to
> a dataframe or matrix than what i have here:
>
> # setup data for tapply
> dt = data.frame(bucket=rep(1:4,25),val=rnorm(100))
> fn = function(x) {
> ret =
>
> c(unname(quantile(x,probs=seq(.25,.75,.25),na.rm=T)),mean(x,na.rm=T))
> }
> a = tapply(dt$val,dt$bucket,fn)
>
> # i seem to be doing way more work than i should here....
> n = names(a)
> mat = NULL
> for (i in 1:length(n)) {
> mat = rbind(mat,unname(unlist(a[i])))
> }
> row.names(mat) = n
>
> thank you!
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>
>
>
>
More information about the R-help
mailing list