Quantcast
Viewing all articles
Browse latest Browse all 206503

Convert a factor column with numbers in k format into numeric without losing any data

I have a factor column which has numbers in it. Some numbers are written in k format, for ex. 99k, 9.25k, 91.9k, etc. while others are written in whole like 998, 575, etc. Two things I want to do-:

  • I want to multiply the numbers having k by 1000 and remove the k.
  • I want to convert this column into a numeric column without losing any data.

If I first convert it into numeric applying as.numeric, the k format numbers will become NAs.

I can't think of anything to resolve this. Can anyone help me with a solution in r?

Following is the Sample data

df=data.frame(
ID = c(1:8),
Likes = c('99k', '997','15.5k', '9.25k','575', '800', '8.5k', '2,400')
)

EDIT I still don't know what is the problem. After trying all the solutions present here, still NAs getting produced. I am providing the link for full data. Kindly go through it and help me to find the problem. The column I am concerned with is 'Likes'.

https://drive.google.com/file/d/1tR0F4SwGmsVjh5NGGpONP6LTaqgDOM4l/view?usp=sharing


Viewing all articles
Browse latest Browse all 206503

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>