Re: [R] Defining partial list of variables

2021-01-05 Thread Bert Gunter
I may not I properly understand the context of this discussion, and, in particular what the my.formula() function does. But if I do, the following, from ?formula, seems relevant and would indicate that the discussion is unnecessary: "There are two special interpretations of . in a formula. The usu

Re: [R] Defining partial list of variables

2021-01-05 Thread Heinz Tuechler
What about the Cs()-function in Hmisc? library(Hmisc) Cs(a,b,c) [1] "a" "b" "c" Steven Yen wrote/hat geschrieben on/am 05.01.2021 13:29: Thanks Eric. Yes, "unlist" makes a difference. Below, I am doing not regression but summary to keep the example simple. > set.seed(123) > data<-matrix(runif

Re: [R] Defining partial list of variables

2021-01-05 Thread Steven Yen
Thanks Eric. Yes, "unlist" makes a difference. Below, I am doing not regression but summary to keep the example simple. > set.seed(123) > data<-matrix(runif(1:25),nrow=5) > colnames(data)<-c("x1","x2","x3","x4","x5"); data     x1    x2    x3 x4    x5 [1,] 0.2875775

Re: [R] Defining partial list of variables

2021-01-05 Thread Eric Berger
wrap it in unlist xx <- unlist(strsplit( )) On Tue, Jan 5, 2021 at 12:59 PM Steven Yen wrote: > Thanks Eric. Perhaps I should know when to stop. The approach produces a > slightly different variable list (note the [[1]]). Consequently, I was not > able to use xx in defining my regression

Re: [R] Defining partial list of variables

2021-01-05 Thread Steven Yen
Thanks Eric. Perhaps I should know when to stop. The approach produces a slightly different variable list (note the [[1]]). Consequently, I was not able to use xx in defining my regression formula. > x<-colnames(subset(mydata,select=c( +    hhsize,urban,male, +    age3045,age4659,age60, # age1

Re: [R] Defining partial list of variables

2021-01-05 Thread Eric Berger
If your column names have no spaces the following should work x<-strsplit(gsub("[\n ]","", "hhsize,urban,male, + gov,nongov,married"),","); x On Tue, Jan 5, 2021 at 11:47 AM Steven Yen wrote: > Here we go! BUT, it works great for a continuous line. With line break(s),

Re: [R] Defining partial list of variables

2021-01-05 Thread Steven Yen
Here we go! BUT, it works great for a continuous line. With line break(s), I got the nuisance "\n" inserted. > x<-strsplit("hhsize,urban,male,gov,nongov,married",","); x [[1]] [1] "hhsize"  "urban"   "male"    "gov" "nongov"  "married" > x<-strsplit("hhsize,urban,male, + gov,no

Re: [R] Defining partial list of variables

2021-01-05 Thread Eric Berger
zx<-strsplit("age,exercise,income,white,black,hispanic,base,somcol,grad,employed,unable,homeowner,married,divorced,widowed",",") On Tue, Jan 5, 2021 at 11:01 AM Steven Yen wrote: > Thank you, Jeff. IMO, we are all here to make R work better to suit our > various needs. All I am asking is an ea

Re: [R] Defining partial list of variables

2021-01-05 Thread Steven Yen
Thank you, Jeff. IMO, we are all here to make R work better to suit our various needs. All I am asking is an easier way to define variable list zx, differently from the way z0 , x0, and treat are defined. > zx<-colnames(subset(mydata,select=c( + age,exercise,income,white,black,hispanic,base,som

Re: [R] Defining partial list of variables

2021-01-05 Thread Jeff Newmiller
IMO if you want to hardcode a formula then simply hardcode a formula. If you want 20 formulas, write 20 formulas. Is that really so bad? If you want to have an abbreviated way to specify sets of variables without conforming to R syntax then put them into data files and read them in using a form

Re: [R] Defining partial list of variables

2021-01-05 Thread Heinz Tuechler
see below Steven Yen wrote/hat geschrieben on/am 05.01.2021 08:14: I constantly define variable lists from a data frame (e.g., to define a regression equation). Line 3 below does just that. Placing each variable name in quotation marks is too much work especially for a long list so I do that wit

[R] Defining partial list of variables

2021-01-04 Thread Steven Yen
I constantly define variable lists from a data frame (e.g., to define a regression equation). Line 3 below does just that. Placing each variable name in quotation marks is too much work especially for a long list so I do that with line 4. Is there an easier way to accomplish thisto define a