[Rtip] In my continuous series of 'Rtips', i came across this annoying set of numerical values that are expressed as strings with commas. for example "20,000,123" that should read as 20000123 . This is common when working with monetary sums or totals. So how would you convert that to readable numbers or integers. I found out that gsub function really good at refomatting this character vector.
> budgets_amounts <- c("20,929,200","782,000,000","100,000,000","14,111,122")
> as.numeric(gsub(",","", budgets_amount))
[1] 20929200 782000000 100000000 14111122
No comments:
Post a Comment
Add any comments if it helped :)