[R] function and apply

From: jose silva <chess.player_at_oninet.pt>
Date: Mon 06 Jun 2005 - 04:56:29 EST


Dear all  

  
 

I think my problem is not complicated but I'm having difficulties to solve it.  

v is a vector: v=c(p1 , p2 , p3 , p4), and f  is a function: f : v -> w , where  

w=c(p1 , p2*(1-p1) , p3*(1-p2)*(1-p1) , p4*(1-p3)*(1-p2)*(1-p1))  

 
 

I write the function f as:  

f<- function(w,x,y,z) {c(w,x*(1-w),y*(1-x)*(1-w),z*(1-y)*(1-x)*(1-w))}  

f(a,b,c,d) it works well.  

 
 

But now I want to apply f to each row of a data frame with 4 columns:  

d<-data.frame(a=seq(1,10), b=seq(11,20), c=seq(21,30),d=seq(31,40))  

t(apply(d,1,f)) is not working?  

I think each element of each row is not corresponding to w,x,y,z and now I'm lost?  

 
 

Can someone help me?  

 
 

thks  

 
 

J. Silva

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jun 06 05:03:34 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:22 EST