Re: [R] loop with variable names

2016-11-05 Thread Bert Gunter
1. Statistically, you probably don't want to do this at all (but that's another story). 2. Programatically, you probably want to use one of several packages that do it already rather than trying to reinvent the wheel. A quick search on rseek.org for "all subsets regression" brought up this:

Re: [R] loop with variable names

2016-11-04 Thread Ista Zahn
It's hard to imagine a situation where this makes sense, but of course you can do it if you want. Perhaps rhs <- unlist(sapply(1:(ncol(df)-1), function(x) apply(combn(names(df)[-1], x), 2, paste, collapse = " + "))) lapply(rhs, function(x) lm(as.formula(paste("y ~", x)), data = df)) --Ista On

[R] loop with variable names

2016-11-04 Thread paolo brunori
Suppose I have the following data: y<-rnorm(10) age<-rnorm(10) sex<-rbinom(10,1, 0.5) edu<-round(runif(10, 1, 20)) edu2<-edu^2 df<-data.frame(y,age,sex,edu,edu2) I want to run a large number of models, for example: lm(y~age) lm(y~age+sex) lm(y~age+sex+edu) lm(y~age+sex+edu+edu2)

Re: [R] Loop in variable names

2011-02-11 Thread Eik Vettorazzi
Date: Wed, 9 Feb 2011 20:15:23 +0100 From: e.vettora...@uke.uni-hamburg.de To: ritacarre...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] Loop in variable names Hi Stella, in your coding 'cut' is a string, not a data object. something like cut - paste(P,i, sep=) table

[R] Loop in variable names

2011-02-09 Thread Rita Carreira
Hello! I would like to do some tables for several variables and I would like to write a loop that does the table for each variable. I should also point out that my data set has several missing observations and sometimes the observations that are missing are not the same for all my variables.

Re: [R] Loop in variable names

2011-02-09 Thread Eik Vettorazzi
Hi Stella, in your coding 'cut' is a string, not a data object. something like cut - paste(P,i, sep=) table(StoreData$CompanyID, !is.na(StoreData[,cut])) should work. hth. Am 09.02.2011 19:02, schrieb Rita Carreira: Hello! I would like to do some tables for several variables and I

Re: [R] Loop in variable names

2011-02-09 Thread jim holtman
Try: for(i in angus) { cut - StoreData[[paste(P, i)]] table(StoreData$CompanyID, !is.na(cut)) } On Wed, Feb 9, 2011 at 1:02 PM, Rita Carreira ritacarre...@hotmail.com wrote: Hello! I would like to do some tables for several variables and I would like to write a loop that does the table

[R] loop through variable names

2009-11-11 Thread Jacob Wegelin
Often I perform the same task on a series of variables in a dataframe, by looping through a character vector that holds the names and using paste(), eval(), and parse() inside the loop. For instance: thesevars-names(environmental) environmental$ToyOutcome-rnorm(nrow(environmental))

Re: [R] loop through variable names

2009-11-11 Thread Gabor Grothendieck
Try this: lm(environmental[c(ToyOutcome, thisvar)]) or lm(ToyOutcome ~., environmental[c(ToyOutcome, thisvar)]) On Wed, Nov 11, 2009 at 6:49 PM, Jacob Wegelin jacobwege...@fastmail.fm wrote: Often I perform the same task on a series of variables in a dataframe, by looping through a