[R] Applying a function to each element of an array

Tuszynski, Jaroslaw W. JAROSLAW.W.TUSZYNSKI at saic.com
Fri Oct 7 21:17:46 CEST 2005


I suspect that loop would be the fastest since it would have the least
memory overhead. You do not want to have too many internal copies of
7000x7000 matrices.

 Jarek 
====================================================\==== 
 Jarek Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">  \ 
 Jaroslaw.W.Tuszynski at saic.com                     `   \ 

 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Tim Smith
Sent: Friday, October 07, 2005 2:48 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Applying a function to each element of an array

Hi,
 
I have a 7000x7000 matrix, and each element is an integer. For each element,
I want to apply the function :
 
wt <- 0
 for(q in 1:count){
 wt <- wt + 0.5^(q-1)
}
 
I get the value of 'count' from the elements in the matrix , and want to
store the corresponding 'wt' value for that element.
 
I suppose I could loop through the matrix, and apply the function to each
element but this would take a really really long time. Are there any quicker
ways to get the same result?
 
many thanks,
 
Tim

		
---------------------------------


	[[alternative HTML version deleted]]

______________________________________________
R-help at 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




More information about the R-help mailing list