Reputation: 1
there is a vector (called f)
f
3 4 8
it indicates which columns from a dataframe (y) should be included in a model. The column names of these columns are FER7, TOJ9, GHY11. Can somebody tell me how I could achieve that
response~factor(FER7)+factor(TOJ9)+factor(GHY111)
with paste or something similar. I will then only need to make it as.formula and feed it the function. There is a way but I just dont see it in th moment
Upvotes: 1
Views: 92
Reputation: 887951
You could try
as.formula(paste0('response~', paste('factor',
'(', names(y)[f],')', sep="",collapse="+")))
#response ~ factor(FER7) + factor(TOJ9) + factor(GHY111)
f <- c(3,4,8)
set.seed(24)
y <- as.data.frame(matrix(sample(1:100, 9*10, replace=TRUE), ncol=9) )
colnames(y) <- c('response', 'T1', 'FER7', 'TOJ9', 'TOJ10',
'TOJ11', 'TOJ12', 'GHY111', 'GHY12')
Upvotes: 1