[R] help about fitdistr funtion

R. Michael Weylandt michael.weylandt at gmail.com
Wed Nov 30 21:03:51 CET 2011

I like to use split() to split your data into groups, then run
lapply() to use fitdistr on each element of the list.


df <- data.frame(X = rnorm(500), ID = sample(letters[1:5], 500, TRUE))

temp <- split(df$X, df$ID)
lapply(temp, fitdistr, "normal")

Though it's just as easy with tapply():

tapply(df$X, df$ID, fitdistr, "normal")


On Wed, Nov 30, 2011 at 10:00 AM, Carlos Javier Rincon Rodriguez
<cjrinconr at unal.edu.co> wrote:
> Hi,
> I have a variable X classified in a lot of groups and I need to run the
> [fitdistr] funtion for each group. I tried with the [by] or the [tapply]
> funtions because my data is organize in two columns  (variable and the
> groups), but neither of these command work. If somebody have a tip to help
> me up I really appreciate it.
> thanks,
>        [[alternative HTML version deleted]]
> ______________________________________________
> 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