Skip to content
Prev 359134 / 398502 Next

using factor variable in the "DO" function

You have competing non-standard evaluation tools in play. I would decouple them with a function (untested):

my fit <- function( DF ) { 
    data.frame( HOSP_NRD = .$HOSP_NRD[1]
        , fitHosp = lm(log(y)~ log(x)+I(log(x)^2)+NCHRONIC+AGE+sex
      , data=DF)
      )
}
dfhosp <- ( dat.2.wide.sub
  %>% group_by(HOSP_NRD)
  %>% do( my_fit( . ) )