Consider the str of dataframe, example, below:
$ A : num 0.00606
$ B : num 0.00466
$ C : num 0.00746
$ D : Factor w/ 2 levels "-0.04","D": 1
..- attr(*, "names")= chr "Tilt"
$ E : Factor w/ 2 levels " 0.00","E": 1
..- attr(*, "names")= chr "Tilt"
How do I convert it such that it becomes:
$ A : num 0.00606
$ B : num 0.00466
$ C : num 0.00746
$ D : num -0.04
$ E : num -0.00
df$D <- as.numeric(as.character(df$D)))
– Adam Quekdput()
your dataframe? – TarJaedf[ sapply(df, is.factor)] <- lapply(df[ sapply(df, is.factor)], function(x) as.numeric(as.character(x)))
– TarJae