[R] Regular Expressions in grep - Solution and function to determine significant figures of a number

Dr. Holger van Lishaut H.v.Lishaut at gmx.de
Thu Aug 23 20:43:25 CEST 2012


Am 22.08.2012, 21:46 Uhr, schrieb Dr. Holger van Lishaut  
<H.v.Lishaut at gmx.de>:

> SignifStellen<-function(x){
>      strx=as.character(x)
>      nchar(regmatches(strx, regexpr("[1-9][0-9]*\\.[0-9]*[1-9]",strx)))-1
> }
>
> returns the significant figures of a number. Perhaps this can help  
> someone.

Sorry, to work, it must read:

SignifStellen<-function(x){
   strx=as.character(x)
   intFront <- nchar(regmatches(strx, regexpr("[1-9][0-9]*\\.", strx)))
   intEnd <- nchar(regmatches(strx, regexpr("\\.[0-9]*[1-9]", strx)))
   intFront+intEnd-2
}

Best regards
H. van Lishaut




More information about the R-help mailing list