[R] function problem
Steve Lianoglou
mailinglist.honeypot at gmail.com
Fri Jul 31 18:47:12 CEST 2009
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
More information about the R-help
mailing list