79569863

Date: 2025-04-12 00:04:47
Score: 0.5
Natty:
Report link

Because, as.numeric() can't be used when your character having commas, dollar signs, or even empty strings.

As an example in my dataset in the price column the class is getting as character. But I want to convert it into numeric. When I directly used as.numeric() I got an warning as 'NAs introduced by coercion'. Then I removed the spaces in the price column -->

gold_ds$Price <- gsub(",", "", gold_ds$Price)

and then did -->

gold_ds$Price <- as.numeric(gold_ds$Price).

It succefully worked for me in R.

Reasons:
  • Whitelisted phrase (-1): worked for me
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Chamudi Abeysinghe