[R] function problem

RRRRRRRRRR! cwalter at usgs.gov
Fri Jul 31 18:53:25 CEST 2009


I am sorry I should have stated the whole problem:

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



Steve Lianoglou-6 wrote:
> 
> Hi,
> 
> On Jul 31, 2009, at 12:25 PM, RRRRRRRRRR! wrote:
> 
>> I have a series of columns that need to be evaluated in various  
>> tables. I
>> need to apply a function in the following manner  
>> somers2(name1,name2). name1
>> is a vector of x inputs for the function which correspond to a  
>> vector of y
>> inputs in name2.
>>
>> y<-rep(c(3,4,5,8),6)
>> z<-rep(c(23,24,25,26,27,28),4)
>> 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)
>> }}}
> 
> You're missing a value for x, so I'm finding it hard to understand  
> what you're trying to do, exactly. From your double for loop, it seems  
> like you just want to compute the function over all vals in X, and  
> each x against all Y.
> 
> Does this help?
> 
> R> x <- LETTERS[1:3]
> R> y <- LETTERS[10:15]
> R> all.vals <- expand.grid(x,y, stringsAsFactors=F)
> R> all.vals[1:3,]
>    Var1 Var2
> 1    A    J
> 2    B    J
> 3    C    J
> 
> R> ans <- lapply(seq(nrow(all.vals)), function(i) paste(all.vals[i,1],  
> all.vals[i,2], sep='(*)'))
> R> ans[1:3]
> [[1]]
> [1] "A(*)J"
> 
> [[2]]
> [1] "B(*)J"
> 
> [[3]]
> [1] "C(*)J"
> 
> -steve
> 
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>    |  Memorial Sloan-Kettering Cancer Center
>    |  Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/function-problem-tp24759253p24759625.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list