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:7),
Likes = c('99k', '997','15.5k', '9.25k','575', '800', '8.5k')
)