Hi Jim,

What exactly do you mean by vectorized. I think outer looks like what I was
looking for. BUT there was a (weighted) distance matrix calculation that I
was trying to vectorize, which wasnt related to this post. Could you proved
a bit more details as to what you were referring to, and maybe an example
as how to vectorize in R?

Thanks,
Sachin

On Mon, Nov 28, 2011 at 3:25 PM, jim holtman <jholt...@gmail.com> wrote:

> 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