I would break it into two steps:
1) Define R-squares for each model
2) Determine what is the highest value
mydf<-data.frame(aa=rpois(8,4),bb=rpois(8,2),cc=rbinom(8,1,.5), happy=c(3,2,2,3,1,3,1,3)) myRes<-sapply(mydf[-ncol(mydf)],function(x){ mylm<-lm(x~mydf$happy) theR2<-summary(mylm)$r.squared return(theR2) }) names(myRes[which(myRes==max(myRes))])
It was assumed that happy
is in your data.frame.
source share