[R] Adding rows to a table with a loop

Weidong Gu anopheles123 at gmail.com
Mon Oct 24 19:36:06 CEST 2011

It surely can be done. One way is to keep track of selected variables
in a set. If a new variable is selected, you expand the selected set
and set the frequency to be one, otherwise just increase the freqency
of the selected variable (if... else).

Also, you might want to have a look at glmulti package which conducts
model selection out of all potential combinations, even including
interactions if you don't have many variables.


Weidong Gu

On Mon, Oct 24, 2011 at 11:58 AM, MJS <taranis.1986 at gmail.com> wrote:
> Hi All,
> Its a bit of a beginners question I'm afraid.
> I have a looped stepwise regression (using MASS and StepAIC) to take random
> predictors out of the total number.  For this example a random sample of 5
> out of a total of 20.  The loop will continue until all combinations of
> variables have been run through the loop.
> The output from each loop can be derived from taking the significant (p)
> coefficients from the summary command, and coding them '1' (if <0.05) or '0'
> (if >0.05), and producing a table of 5 columns for each of the predictors
> entered.
> The table produced in the loop is much smaller than the input table.  Is
> there a way to produce a results table using the original column titles of
> the input table which can be matched to the subset predictors table, where
> if the variable was not in the subset its row value is 'NA'?
> I hope that makes sense.
> Cheers In advance,
> Matt
> --
> View this message in context: http://r.789695.n4.nabble.com/Adding-rows-to-a-table-with-a-loop-tp3933634p3933634.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> 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