I have a data frame with a column that contains numeric values, which represent the price.
| ID | Total |
|---|---|
| 1124 | 12.34 |
| 1232 | 12.01 |
| 1235 | 13.10 |
I want to split the column Total by "." and create 2 new columns with the euro and cent amount. Like this:
| ID | Total | Euro | Cent |
|---|---|---|---|
| 1124 | 12.34 | 12 | 34 |
| 1232 | 12.01 | 12 | 01 |
| 1235 | 13.10 | 13 | 10 |
| 1225 | 13.00 | 13 | 00 |
The euro and cent column should also be numeric.
I tried:
df[c('Euro', 'Cent')] <- str_split_fixed(df$Total, "(\\.)", 2)
But I get 2 new columns of type character that looks like this:
| ID | Total | Euro | Cent |
|---|---|---|---|
| 1124 | 12.34 | 12 | 34 |
| 1232 | 12.01 | 12 | 01 |
| 1235 | 13.10 | 13 | 1 |
| 1225 | 13.00 | 13 |
If I convert the character columns (euro and cent) to numeric like this: as.numeric(df$Euro) the 00 cent value turns into NULL and the 10 cent turn into 1 cent.
Any help is welcome.