On 25/02/2015 8:55 PM, ce wrote:
> Dear all,
> 
> I would like to count how many digits are there on the left of a the dot of a 
> numeric variable
> 
> a=0.0001

This will depend on the formatting used.  If default formatting used by
as.character() is fine, then

nchar(sub("^[[:digit:]]*[.]", "", a))

should work. (Note that default formatting is scientific for 0.0001.) If
you want some other formatting, then format first, and pass a character
object, e.g.

chars <- format(a, scientific = FALSE)
nchar(sub("^[[:digit:]]*[.]", "", chars))

Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to