y=sapply(1:nrow(x), function(i) sapply(1:ncol(x), function(j)
getrc(i, j)))
Arvin Zolfaghari, Ph.D.
Aon Benfield | Aon Benfield Analytics
55 Bishopsgate, London, EC2N 3BD, UK
t: +44 20 7522 8241 | f: +44 20 7522 3846| M: +44 78 8940 6637
e: arvin.zolfaghari@aonbenfield.com | w:
www.AonBenfield.com<http://www.aonbenfield.com/>
From: Arvin Zolfaghari
Sent: 08 November 2010 14:35
To: 'Markus.Gesmann@lloyds.com'
Subject: question
Hi List,
I am trying to apply a
function to all elements of a matrix. I can use two consequent ' for'
loops, but it is really slow process. I can also use the sapply as follows,
but it is 10% faster, is there any other faster way (like fft)?
I got a matrix of x=matrix(0,1000,2000)
I want to load it with myfunction
first option:
For ( i in nrow(x)){
For(j in nrow(x)){
x=myfunction(i,j)
}}
second option:
t(sapply(1:nrow(x), function(i) sapply(1:ncol(x), function(j)
getrc(i, j))))
both option 1 and 2 work, but so slow. I appreciate your help.
thanks
Alireza
[[alternative HTML version deleted]]