[R] avoiding 'for' loop

Taka Matzmoto sell_mirage_ne at hotmail.com
Wed Nov 1 07:48:14 CET 2006


Hi R users

I have a 1000 * 11 matrix (or data.frame). The first 10 columns consist of 0 
or 1 (i.e., binary data) and the last column consists of real values.

I would like to run a logistic regression with the first binary column as a 
dependent variable, and the second binary column and the last real value 
column as independent variables. After this, I save 'Z' value for the binary 
independent variable. Then, with the first binary column as a dependent 
variable, and the third binary column and the last real value column as 
independent variables. After this, I saved 'Z' value for the binary 
independent variable, keeping doing this ...

Here is my simple R codes

logistic.z.value <-c()

for (i in 1:9)
    {
        for (j in (i+1):10)
            {
                model <- glm(X[,i] ~ X[,11] + X[,j], family=binomial(logit))
                logistic.z.value <- 
append(logistic.z.value,coef(summary(model))[3,3])
            }
    }

I would like to avoid using 'for' loop command. Is there any way for me to 
use some fast codes instead of using 'for' loop?

Many thanks

Taka,

_________________________________________________________________
Stay in touch with old friends and meet new ones with Windows Live Spaces



More information about the R-help mailing list