[R] mapply

From: Mark Leeds <markleeds_at_verizon.net>
Date: Sun, 23 Mar 2008 11:06:05 -0400


In an earlier post, a person wanted to divide each of the rows of

rawdata by the row vector sens so he did below but didn't like it and

asked if there was a better solution.  

rawdata <- data.frame(rbind(c(1,2,2), c(4,5,6))) sens <- c(2,4,6)  

temp <- t(rawdata)/sens

temp <- t(temp)

print(temp)  

Gabor sent three other solutions and I understood 2 of them but not the one below.  

I think I understand mapply a little but what I don't understand how

it knows to take the rows of rawdata and then I guess recycle sens ?

how did the mapply know not to take the columns of rawdata and do

something to them ? or maybe mapply does things element by element and it is doing more

complex recycling ? I guess I don't really understand mapply that well but I did

read the help of it.  

Thanks so much for any enlightenment from anyone besides Gabor. I bother him enough already

and he does more than enough.  

tempc <- data.frame(mapply("/", rawdata, sens))

print(tempc)  

                                 Mark

 

 

 

 

 


	[[alternative HTML version deleted]]

______________________________________________
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. Received on Sun 23 Mar 2008 - 15:09:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 23 Mar 2008 - 16:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive