Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transforming pattern with gsub

Tags:

regex

r

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

like image 794
GEX_HEX_420 Avatar asked Sep 18 '26 02:09

GEX_HEX_420


1 Answers

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

> gsub("([0-9]+)(e)+(-)", "\\1x10^\\3", eg)
[1] "5.4748554x10^-14"
> 
like image 60
U12-Forward Avatar answered Sep 19 '26 18:09

U12-Forward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!