[R] "by" function "half-working" when used in a custom function

Gabor Grothendieck ggrothendieck at gmail.com
Mon Feb 25 16:55:07 CET 2008


Please give minimal reproducible examples.
The data and a test driver were missing.
See last line to every message to r-help.

The problem is discussed here:
http://tolstoy.newcastle.edu.au/R/help/06/08/32017.html

On Mon, Feb 25, 2008 at 10:05 AM, vincent chouraki <vchouraki at yahoo.fr> wrote:
> Dear R users,
>
> I'm trying to save the results of separate logistic regression analyses of a dataset according to a categorical factor. For that, I first used a "by" function such as following :
>
> temp <- by( data, data$categorical.factor , function(x) summary( glm( formula = data$var1 ~ data$var2 , data = x , family = binomial("logit"))))
>
> and it worked perfectly well
>
> Next I tried to create a custom function that contains the latter syntax
>
> regtab <- function(category, arg1, arg2 , data){
>
>  temp <-by( data, category , function(x) summary( glm( formula= arg1 ~ arg2 , data=x , family = binomial("logit"))))
>
>  temp
>
> }
>
> the resulting object of this function is a list with the correct subgroup categories as its element's names but with the results of the entire dataset logistic regression as its elements.
>
> I can't figure out what's going on. Do you have any clues ?
>
> Many thanks in advance,
>
> Vincent Chouraki,
> Interne de Santé Publique,
> CHRU-Lille, France.
>
>
>
>
>
>      _____________________________________________________________________________
>
>
>        [[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