On Jul 12, 2010, at 10:09 AM, Raghu wrote:
When I just run a for loop it works. But if I am going to run a for
loop
every time for large vectors I might as well use C or any other
language.
The reason R is powerful is becasue it can handle large vectors
without each
element being manipulated? Please let me know where I am wrong.
for(i in 1:length(news1o)){
+ if(news1o[i]>s2o[i])
+ s[i]<-1
+ else
+ s[i]<--1
+ }
Perhaps:
s <- 2*( news1o > s2o[1:length(news1o)] ) - 1
...which I think will throw errors under pretty much the same
conditions that would cause errors in that loop.
--
David Winsemius, MD
West Hartford, CT
______________________________________________
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.