0

I'm practically a total beginner but anyway - trying to convert column values to numeric values.

If I go:

head(df$Average.Amount) returns: "1,646.15" "1,425.00" "2,487.50" "2,200.00" "2,456.25" "2,412.50"

class(df$Average.Amount) returns: character

head(as.numeric(df$Average.Amount)) returns: NA NA NA NA NA NA

I tried noquote to take away quotations...

Let me know what you think!

Hbells
  • 1

1 Answers1

1

As @thelatemail says, your as.numeric() doesn't work because of the commas. Luckily, you can use readr::parse_number() for the same task.

numbers <- c("1,646.15", "1,425.00", "2,487.50", "2,200.00", "2,456.25")

as.numeric(numbers)
#> Warning: NAs introduced by coercion
#> [1] NA NA NA NA NA

readr::parse_number(numbers)
#> [1] 1646.15 1425.00 2487.50 2200.00 2456.25

Created on 2022-06-26 by the reprex package (v2.0.1)

Samuel Calderon
  • 641
  • 3
  • 13