Take a look at 'outer'  and vectorized your function.  Also look at
'expand.grid'.

On Sunday, November 27, 2011, Sachinthaka Abeywardana <
sachin.abeyward...@gmail.com> wrote:
> Hi All,
>
> I want to do something along the lines of:
> for (i in 1:n){
>    for (j in 1:n){
>        A[i,j]<-myfunc(x[i], x[j])
>    }
> }
>
> The question is what would be the most efficient way of doing this. Would
> using functions such as sapply be more efficient that using a for loop?
>
> Note that n can be a few thousand. Thus atleast a 1000x1000 matrix.
>
> Thanks,
> Sachin
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to