'How to bin data with specific conditions in r
I have a data set that requires me to categorise data to consider changes over time. I want to create a new column that codes a data range. For example, I would want to add a column to the following data set called 'category' where category is 1 when V1 is between 10-13; 2 when V1 is between 14-16; and 3 when V1 is between 17-20.
Data<-data.frame(
X = factor(c("SU", "Staff")),
V1 = c(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))
I previously used the following code to create 5 equal bins, but I now want to specify the range as above:
binning <- Data %>% mutate(Category=ntile(Data$'V1', 5))
Any help would be appreciated and I am new to r so simple language would be welcomed.
Many thanks, Laura
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
