FAQ
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,

Search Discussions

  • R. Michael Weylandt at Nov 30, 2011 at 8:03 pm
    I like to use split() to split your data into groups, then run
    lapply() to use fitdistr on each element of the list.

    E.g,

    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")

    Michael

    On Wed, Nov 30, 2011 at 10:00 AM, Carlos Javier Rincon Rodriguez
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedNov 30, '11 at 3:00p
activeNov 30, '11 at 8:03p
posts2
users2
websiter-project.org
irc#r

People

Translate

site design / logo © 2022 Grokbase