I would like to replace numeric values with strings. numeric range is between -1 and 1 my dput of a df is below.
structure(list(m = c(-0.226, 0.11, 0.143, -0.095, -0.007, -0.232,
-0.258, -0.438, -0.199, -0.419, -0.41, -0.271, -0.176, -0.33,
-0.335, -0.59, -0.724, -0.161, -0.237, -0.223, -0.041, -0.627,
-0.37, 0.055, -0.215, -0.287, -0.378, 0.006, -0.381, -0.598,
-0.179, -0.259, 0.147, -0.08, 0.172, 0.035, -0.458, -0.254, -0.373,
-0.319)), .Names = "m", row.names = c(NA, -40L), class = "data.frame")
When i run the below code it does not give the intended outcome.
m[m >= 0.3] <- "a"
m[(m < 0.3 & m >= 0.2)] <- "b"
m[(m < 0.2 & m >= 0.1)] <- "c"
m[(m < 0.1 & m >= 0.05)] <- "d"
m[(m < 0.05 & m >= 0)] <- "e"
m[(m < 0 & m >= -0.05)] <- "f"
m[(m < -0.05 & m >= -0.1)] <- "g"
m[(m < -0.1 & m >= -0.2)] <- "h"
m[(m < -0.2 & m >= -0.3)] <- "i"
m[m < -0.3] <- "j"
I also tried with adding a "," at the end like the below :
m[m < -0.3,] <- "j"
I believe the code is quite self-explanatory : i would like to change the values in a range by a character string. The inequality with negative values does not seem to work...
Thanks.