[R] For each element in vector do...

From: Andrej Kastrin <andrej.kastrin_at_siol.net>
Date: Wed 18 Jan 2006 - 01:30:58 EST


Dear R useRs,

I have a vector with positive and negative numbers: A=c(0,1,2,3,0,4,5)

Now if i-th element in vector A is > 0, then i-th element in vector B is a+1
else i-th element in vector b=a (or 0)

vector A: 0 1 2 3 0 4 5
vector B: 0 2 3 4 0 5 6

What's the right way to do this. I still have some problems with for and if statements...

Cheers, Andrej



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jan 18 01:38:59 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:04 EST