<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Evan Zane Macosko wrote:
<blockquote TYPE=CITE>Hi everyone,
<p>I'm translating into R some programs I worked through in Matlab to
<br>calculate the angle between two vectors (very large--like 6200 rows
in
<br>each vector). In Matlab, I used a series of nested for loops,
because I
<br>was calculating the angles between many pairs of vectors. I know
for
<br>loops are not desirable in R code, so I was wondering if anyone could
<br>recommend a faster way to complete this task. Also, I have NAs
in my
<br>vectors--I've had trouble performing various operations on my vectors
in R
<br>because of these NAs.
<p>Any advice on this would be greatly appreciated.</blockquote>
<p><br>As far as I know, the use of apply (sapply and lapply) would make
things run faster than 'for' loops.
<br>
<p>About the NAs, you may want to ignore the vectors which have a NA coordinate,
or may be do something else...
<br>to have a foot in this, you may try the help for the functions 'is.na'
and 'na.action'.
<br>
<br>
<p>I hope it helps,
<br>
<br>
<br>
<p>Laurent
<br>
<br>
<pre>--
Laurent Gautier CBS, Building 208, DTU
PhD. Student D-2800 Lyngby,Denmark
tel: +45 45 25 24 85 <A HREF="http://www.cbs.dtu.dk/laurent">http://www.cbs.dtu.dk/laurent</A></pre>
</html>