[R] in continuation with the earlier R puzzle
David Winsemius
dwinsemius at comcast.net
Mon Jul 12 18:24:09 CEST 2010
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
More information about the R-help
mailing list