0

I have a list of random numbers.

x=sample(1:1000, 3)

Is there a simple way to get a list of range values in which each element falls in?

id=seq(1, 1000, by=50)

 [1]   1  51 101 151 201 251 301 351 401 451 501 551
[13] 601 651 701 751 801 851 901 951

eg.

x
[1] 637 374  68

distribution
[1] "601~650" "351~400" "51~100"
Sati
  • 716
  • 6
  • 27

1 Answers1

1

Try this easy solution using findInterval:

cbind(x,lim_inf=id[findInterval(x,id)],lim_sup=id[findInterval(x,id)+1])
       x lim_inf lim_sup
[1,] 378     351     401
[2,] 609     601     651
[3,] 496     451     501
Terru_theTerror
  • 4,918
  • 2
  • 20
  • 39