Consider e.g. the following data frame:
data <- matrix(c(12, 6, 13, 15, 2, 7, 7, 14), nrow = 4)
data <- as.data.frame(data)
Variable 1 | Variable 2 |
---|---|
12 | 2 |
6 | 7 |
13 | 7 |
15 | 14 |
Suppose that the values of the Variable 2 are instances of two categories; category 1 (values < 10) and category 2 (values >= 10).
How could I replace the second column by the category of its value? The resulting data frame would be:
Variable 1 | Variable 2 (Category) |
---|---|
12 | Category 1 |
6 | Category 1 |
13 | Category 1 |
15 | Category 2 |