1

I have a dataset that contains the number of app installers, the data recorded with units M and K, like: 19M, 199K.

How to replace the prefixes with their values to convert values to numeric.

k to e+3

M to e+6

2

1 Answer 1

2

Edit: For values that have non-integer values.

x <- c("19M","20K","1K", "1.25M", "1.5K"); x
x <- sub("M", "e6", x); x
x <- sub("K", "e3", x); x
as.numeric(x)
[1] 19000000    20000     1000  1250000     1500

For integer values, the following is sufficient.

x <- c("19M","20K","1K")

x <- sub("M","000000", x)
x <- sub("K","000", x)
as.numeric(x)

1.9e+07 2.0e+04 1.0e+03
Sign up to request clarification or add additional context in comments.

1 Comment

1.5K is not 1.5e+00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.