From: ManojW <manojsw_at_gmail.com>

Date: Mon 30 May 2005 - 15:19:07 EST

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:25:04 2005

Date: Mon 30 May 2005 - 15:19:07 EST

OK...x[min(which(x!=0)):length(x)] does the trick!

I guess the coffee is slowly but surely working! .

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.

Manoj

- Original Message ----- From: ManojW To: R-help Sent: Monday, May 30, 2005 2:00 PM Subject: Vector Manipulation

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.

Regards

Manoj

[[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:25:04 2005

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