[R] automate multiple object creation

waltzmiester cwalte03 at shepherd.edu
Fri Jul 31 17:40:25 CEST 2009



x<-c("a","b","c","d","e","f")
y<-rep(c(3,4,5,8),6)
z<-rep(c(23,24,25,26,27,28),6)
name1<-sprintf("Pred_pres_%s_indpdt[,%s,,]",x,y)
name2<-sprintf("population[,%s]",z)

rank<-function(i,j){

	for(i in name1){
	for(j in name2){
somers2(i,j)
}}}

rank(name1,name2)













waltzmiester wrote:
> 
> I believe this is a little bit closer:
> 
> rank<-function(i,j){
> 
> 	for(i in name1){
> 	for(j in name2){
> somers2(i,j)
> }}}
> 
> rank(name1,name2)
> 
> 
> 
> bu still not there
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> waltzmiester wrote:
>> 
>> I appreciate all the help I have received from this list and also not
>> being flamed because I am new to R. Many of my problems are in automation
>> so far.
>> 
>> I am trying to create multiple objects that are outputs of functions.
>> Here are the tasks:
>> 
>> aGAM<-somers2(Pred_pres_a_indpdt[,3,,],population[,23])
>> aGBM<-somers2(Pred_pres_a_indpdt[,4,,],population[,23])
>> cGLM<-somers2(Pred_pres_a_indpdt[,5,,],population[,23])
>> cRF<-somers2(Pred_pres_a_indpdt[,8,,],population[,23])
>> 
>> bGAM<-somers2(Pred_pres_b_indpdt[,3,,],population[,24])
>> bGBM<-somers2(Pred_pres_b_indpdt[,4,,],population[,24])
>> bGLM<-somers2(Pred_pres_b_indpdt[,5,,],population[,24])
>> bRF<-somers2(Pred_pres_b_indpdt[,8,,],population[,24])
>> 
>> ...and so on through the letter f.
>> 
>> so the variables (x,y,z in this example) are as follows:
>> 
>> xGAM<-somers2(Pred_pres_x_indpdt[,y,,],population[,z])
>> 
>> the GAM, GBM, GLM, and RF are stored in a column y in
>> "Pred_pres_x_indpdt."
>> x is denoting a species, which corresponds to column z in "population,"
>> so a:f == 23:28
>> 
>> ~~~~~~~
>> This may be pushing it, but it would be great if I could get all of these
>> in a matrix of dim[1,96]
>> 
>> Here is what I have so far:
>> 
>> x <- c("a","b","c","d","e","f")
>> nums <- c(23:28)
>> 
>> rank<-function(x){
>> 
>> for(y in nums){
>> 
>> xGAM<-somers2(Pred_pres_x_indpdt[,3,,],population[,y])
>> xGBM<-somers2(Pred_pres_x_indpdt[,4,,],population[,y])
>> xGLM<-somers2(Pred_pres_x_indpdt[,5,,],population[,y])
>> xRF<-somers2(Pred_pres_x_indpdt[,8,,],population[,y])
>> 
>> rank(x)
>> 
>> }}
>> 
>> #for each species, there is 16 columns of output, so a total of 96
>> columns is needed
>> 
>> x_matrix<-matrix(c(xGAM[1:2],Evaluation.results.TSS[[1]][1,3:4],xGBM[1:2],Evaluation.results.TSS[[1]][2,3:4],
>> xGLM[1:2],Evaluation.results.TSS[[1]][3,3:4],xRF[1:2],Evaluation.results.TSS[[1]][4,3:4]),
>> nrow=1,ncol=16,
>> dimnames=list(c(""),
>> c("x_gam_AUC", "x_gam_Dxy","x_gam_TSS","x_gam_Cutoff","x_gbm_AUC",
>> "x_gbm_Dxy","x_gbm_TSS","x_gbm_Cutoff",
>> "x_glm_AUC", "x_glm_Dxy","x_glm_TSS","x_glm_Cutoff","x_rf_AUC",
>> "x_rf_Dxy","x_rf_TSS","x_rf_Cutoff")))
>> 
>> 
>> Thanks again for helping me out.
>> 
>> Chris
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/automate-multiple-object-creation-tp24756632p24758066.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list