简体   繁体   中英

How to group values within a column in R?

I have a data set where I have a column that has values 0 - 1,000. I want to group the values so 0 - 200 is denoted as 1, 200 - 600 as 2, and 600 - 1,000 as 3. Then I want the values 1,2,3 in one column. How do I do this? I am new to R.

Use findInterval . Example:

x <- c(0, 199, 200, 201, 599, 600, 601, 1000)
findInterval(x, c(0, 200, 600))
#[1] 1 1 2 2 2 3 3 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM