Re: [R] Computing calculation among two vectors

2013-09-25 Thread arun
11:46 AM Subject: Re: [R] Computing calculation among two vectors A cute problem. Is it homework? Hint: ?outer (will provide a much simpler solution than those given below) -- Bert On Wed, Sep 25, 2013 at 8:34 AM, arun wrote: Hi, >You could also try: >res1<-sapply(y,

Re: [R] Computing calculation among two vectors

2013-09-25 Thread Bert Gunter
A cute problem. Is it homework? Hint: ?outer (will provide a much simpler solution than those given below) -- Bert On Wed, Sep 25, 2013 at 8:34 AM, arun wrote: > Hi, > You could also try: > res1<-sapply(y,function(i) {x1<- expand.grid(x,x);fun1<- function(a,op,b){ > f1<- match.fun(FUN=op); f1(

Re: [R] Computing calculation among two vectors

2013-09-25 Thread arun
Hi, You could also try: res1<-sapply(y,function(i) {x1<- expand.grid(x,x);fun1<- function(a,op,b){ f1<- match.fun(FUN=op); f1(a,b)};fun1(x1[,1],i,x1[,2])}) row.names(res1)<- row.names(res)  identical(res1,res) #[1] TRUE A.K. - Original Message - From: arun To: R help Cc: Sent: Wedne

Re: [R] Computing calculation among two vectors

2013-09-25 Thread arun
Hi, Try: x<- 1:4  y<- c("*","/","-","+") res<-sapply(y,function(i) {x1<-expand.grid(x,x); unlist(lapply(paste0(x1[,1],i,x1[,2]),function(u) eval(parse(text=u}) row.names(res)<- as.character(interaction(expand.grid(x,x),sep="_")) head(res) #    *   /  - + #1_1 1 1.0  0 2 #2_1 2 2.0  1 3 #3_1 3