Skip to content
Prev 257198 / 398506 Next

mapply to lapply

Dear Andreas,
I would like to thank you for your reply.
I have tried two alternatives but none of the two worked out:

F2[i+1,j+1]<-sum(lapply(1:nrow(cells), function(rowInd) Fwithcellvalue(i=i,j=j,a=cells[rowInd,2],b=cells[rowInd,4],c=cells[rowInd,1],d=cells[rowInd,3],e=cells[rowInd,5])))

this one is executed : takes like 2 mins to return(which is normal) but returns the following

^@Error in sum(lapply(1:nrow(cells), function(rowInd) Fwithcellvalue(i = i,  : 
  invalid 'type' (list) of argument


afterwards I tried to change the function definition so to pass i,j inside:

This one does not execute at all 

F2[i+1,j+1]<-sum(lapply(1:nrow(cells), function(rowInd,i,j) Fwithcellvalue(i=i,j=j,a=cells[rowInd,2],b=cells[rowInd,4],c=cells[rowInd,1],d=cells[rowInd,3],e=cells[rowInd,5])))
Error in paste("f", i, j, "(a,b,c,d)", sep = "") : 
  argument "i" is missing, with no default


What do you think I should try out now?

Vielen Dank
Alex
--- On Mon, 4/18/11, Andreas Borg <andreas.borg at unimedizin-mainz.de> wrote: