0

I'm trying to create a group id column in a dataframe based on a set of endpoints I have.

For an example of whata the dataset might look like:

test_endpoints = tibble(ep = c(1,6, 10 , 17, 20) )
test_tbl = tibble(n = rnorm(mean = 15, sd = 10,n = 100))

What I want to do is to somehow join test_endpoints to test_tbl and then have a column in the resulting table with a group depending where in the endpoints it falls.

i.e. if column n in test_tbl is between 1 and 6 then group_id shoud be 1, if between 6 and 10 then 2, etc.

I can do this manually using a case_when function but that becomes complicated if I have say 1000 endpoints.

Is there some way in the tidyverse to create this grouping?

Thanks for the help.

Rafael Velásquez
  • 337
  • 1
  • 3
  • 14

0 Answers0