Mateus Maciel
Mateus Maciel

Reputation: 161

Can't convert text to numeric

I've downloaded the information about energy outages, from a text file. This is what the data looks like, in my R environment:

 bairro            consumidores dec       ano
  <chr>             <chr>        <chr>   <dbl>
1 AGUA GRANDE        44.417       5,68    2017
2 ALDEIA CAMPISTA    38.589       3,42    2017
3 ALVORADA           27.660       2,74    2017
4 AREIA BRANCA       124.193      7,29    2017
5 ARI FRANCO         65.563       9,79    2017
6 BAEPENDI           11.056       12,09   2017

However, I can't merge this table with another that I have and also I can't convert the dec column to numeric.

Upvotes: 0

Views: 80

Answers (1)

Georgery
Georgery

Reputation: 8117

Assuming your dataframe is called df:

df$dec <- as.numeric(gsub(",", ".", df$dec))

Upvotes: 1

Related Questions