<!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).&nbsp; In Matlab, I used a series of nested for loops,
because I
<br>was calculating the angles between many pairs of vectors.&nbsp; 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.&nbsp; 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>&nbsp;
<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>&nbsp;
<br>&nbsp;
<p>I hope it helps,
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<p>Laurent
<br>&nbsp;
<br>&nbsp;
<pre>--&nbsp;
Laurent Gautier&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CBS, Building 208, DTU
PhD. Student&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D-2800 Lyngby,Denmark&nbsp;&nbsp;&nbsp;
tel: +45 45 25 24 85&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://www.cbs.dtu.dk/laurent">http://www.cbs.dtu.dk/laurent</A></pre>
&nbsp;</html>