[R] Re: Vector Manipulation

From: ManojW <manojsw_at_gmail.com>
Date: Mon 30 May 2005 - 15:12:54 EST

I should clarify that I tried x[cumsum(x)!=0] but the problem is that I might have negative numbers in the vector that can potentially make cumsum(x) equal to zero somewhere down the line in the vector.


  Dear All,

      For any given vector, I want to extract a sub-vector such that the new vector skips all zeros, if any , at the start of vector. Is it possible to achieve this w/o looping?

      E.G :     >    x    = c(0,0,1,2,3,4,5,0,0,8,9)
                   >    y    = somefunc(x);

> y
[1] 1 2 3 4 5 0 0 8 9 In the example above, I want to skip the two leading zeroes till I hit the non-zero (1 in the above case). I also want to retain all zero after the first non-zero digit (again 1 in this case). Hope I am not confusing you guys. Thanks in advance for your help.



	[[alternative HTML version deleted]]

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 Mon May 30 15:19:15 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:15 EST