library(MASS)

dat <- data.frame(
    col1=as.factor(sample(1:4, 100, T)),
    col2=as.factor(sample(1:4, 100, T)),
    col3=as.factor(sample(1:4, 100, T)),
    isi=rnorm(100)
)

dat <- split(dat, as.factor(sample(1:3, 100, T)))
lapply(dat, function(x, densfun) fitdistr(x$isi, densfun), 'normal')

Not used fitdistr before, and without data, I can't help with the error you
note below (which may well still occur)

Hope this helps.





On Mon, Mar 8, 2010 at 1:29 PM, Dgnn <sharkbrain...@gmail.com> wrote:

>
> I have split my original dataframe to generate a list of dataframes each of
> which has 3 columns of factors and a 4th column of numeric data.
> I would like to use lapply to apply the fitdistr() function to only the 4th
> column (x$isi) of the dataframes in the list.
>
> Is there a way to do this or am I misusing lapply?
>
> As a second solution I tried splitting only the numeric data column to
> yield
> a list of vectors and then using
> lapply(myList, fitdistr, densfun='gamma',start=list(scale=1, shape=2))
> returns the error:
> Error in optim(x = c(305, 290, 283, 363, 331, 293, 304, 312, 286, 339,  :
> non-finite finite-difference value [2]
> In addition: Warning message:
> In dgamma(x, shape, scale, log) : NaNs produced
>
> However, if I use fitdistr(myList[[i]]) on each element of the list, there
> are no errors.
>
> Thanks in advance for any comments.
>
> -jason
> --
> View this message in context:
> http://n4.nabble.com/lapply-and-list-indexing-basics-after-realizing-I-wasn-t-previously-subscribed-sorry-tp1584053p1584053.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to