Prakhar Agarwal
Prakhar Agarwal

Reputation: 5

Use of gsub function to clean a column in a data frame in R

I have a column showing total assets of some people in Rs 3,94,24,827 ~ 3 Crore+ this format. I want this column to show only numeric data i.e. 39400000 for the above value and same for every row. How to do this in R.

Upvotes: 0

Views: 217

Answers (1)

Onyambu
Onyambu

Reputation: 79318

What if you try something like

text=“Rs 3,94,24,827 ~ 3 Crore+”
gsub(“\\D”,””,gsub(“,[2].+”,”00000”,text))
[1] “39400000”

To obtain the number alone;

gsub(“(~.*)|\\D”,””,text)
[1]”39424827”

Upvotes: 1

Related Questions