How to convert negative values in variable, class <chr>, into numeric/integer without receiving NAs?

Viewed 458

Thank you very much in advance for your help!

In my dataframe(x) I want to convert the values in variable 1 and 2 into numerical/integer as well and also replace the "," into "." class(x) 1 "tbl_df" "tbl" "data.frame"

I already managed for variable 1: x$1 <- as.numeric(str_replace(x$1, ",", "."))

enter image description here

For variable 2 I get NAs for the negative elements in the variable when I tried to convert with x$2 <- as.numeric(str_replace(x$2, ",", ".")) and x$2 <- as.integer(str_replace(x$2, ",", "."))

enter image description here

I tried also with as.numeric(as.character(factor)). I got the NAs in very line in variable 2 wherever I had negative values. For the positive ones I could manage to convert them with as.integer.

Could you help me please to convert the negative values in variable 2 into numerical/integer?

I really appreciate your support!

0 Answers
Related