[R] help
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Mon Mar 15 12:26:27 CET 2004
Manica wrote:
> I want to extract the first non-zero digit of any vector, as for example
> from a<-runif(100,0,1).
> Tried it using grep (...) but didn´t work.
>
> Any help is very much appreciated.
> Thanks,
> Manica
>
>
How about:
a <- runif(10, 0, 1)
b <- as.character(a)
nonzero <- regexpr("[1-9]", b)
as.numeric(substr(b, nonzero, nonzero))
-sundar
P.S. in the future, it would be helpful to see an example of the output
you expect to avoid any confusion in the question.
More information about the R-help
mailing list