0

I'm looking to run the fitDist function on columns in a dataframe using sapply and save the output to a dataframe, using something like the following:

data.frame(sapply(df, fitDist))

Run singularly, fitDist outputs it's results as a list:

output$family
output$parameters
output$type
output$call
output$y
output$weights
output$G.deviance
output$N
output$df.fit
output$df.residual
output$aic
output$sbc
output$method
output$vcov
output$Allpar
output$mu
output$mu.link
output$sigma
output$sigma.coefficients
output$sigma.link
output$nu
output$nu.coefficients
output$nu.link
output$tau
output$tau.coefficients
output$tau.link
output$residuals
output$rqres
output$failed
output$fits

However, all I really need from the output is the second value from output$family[2] ["Exponential generalized beta 2 (i.e. of the second kind)"], but I'm not sure how to adjust the sapply call to return just this value.

Any suggestions on how adjust the command so that it only produces a dataframe that returns this value would be greatly appreciated.

TDeramus
  • 77
  • 5
  • 6
    Create an anonymous function. Try `data.frame(sapply(df, function(x) fitDist(x)$family[2]))`. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 20 '23 at 15:14
  • Is that syntax correct? I can't shake the idea there should be a , or {} around the fitDist(x) bits. – TDeramus Jul 20 '23 at 17:49
  • Nevermind. That appears to be working. Thank you so much @MrFlick! – TDeramus Jul 20 '23 at 18:14

0 Answers0