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.
Asked
Active
Viewed 208 times
0
-
You have this `Rs 3,94,24,827 ~ 3 Crore+` and want this `39424827`? – Rui Barradas Jan 08 '18 at 17:50
-
Please post some data by editing the question with the output of `dput(head(data, 20))`, replacing `data` by the name of your dataset. Also, in order to ask a better question please read [How to ask a good question](https://stackoverflow.com/help/how-to-ask) and [Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve) and [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Rui Barradas Jan 08 '18 at 17:56
1 Answers
1
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”

Onyambu
- 67,392
- 3
- 24
- 53
-
Looks like you pasted some fancy left and right quotes into your answer --- they'll need to be replaced with standard `"` to work in R. – Gregor Thomas Jan 08 '18 at 18:27
-
I see what you mean. It’s just that I am using my phone to answer the question. – Onyambu Jan 08 '18 at 18:49
-
@Onyambu The solution works, but in gsub(“\\D”,””,gsub(“,[2].+”,”00000”,text)) you have hard-coded the number of zeroes to append, whereas the column which I was trying to clean contains more than 1 record. Thanks for the help – Prakhar Agarwal Jan 09 '18 at 14:56
-