Odd behavior when converting columns of dataframe to factors
I am trying to convert all the columns of a dataframe to factors. However,
the conversion to factors make all my entries become string instead of
numeric. See example:
df <- data.frame(a = c(1,2,3), b = c(4,5,6))
df_factor <- apply(df, 2, factor)
This is what I get:
#> df_factor
# a b
#[1,] "1" "4"
#[2,] "2" "5"
#[3,] "3" "6"
Would you have an idea as to where the problem is coming from?
Thanks,
No comments:
Post a Comment