Home > Net >  Transforming pattern with gsub
Transforming pattern with gsub

Time:10-27

Why does this:

gsub("([0-9]) (e) (-)","\\1^x10^\\3",eg)

Turn this: eg<-5.4748554e-14

Into this:

5.4x10^-14

I want to make it this:

5.4748554x10^-14

CodePudding user response:

Move inside the parenthesis to make it a single first group match:

> gsub("([0-9] )(e) (-)", "\\1x10^\\3", eg)
[1] "5.4748554x10^-14"
> 
  • Related