Skip to content
Prev 388920 / 398513 Next

Finding if numbers fall within a range

Hello,


I think I've found a solution, but it's not producing the same answer as
what you're expecting. I think you might've mixed up row and column a few
times, but you should be able to alter the following to your needs. Also,
see ?.bincode:


EB <- matrix(data = c(
      1, 271, 179, 359, 178,
     57, 279, 279,  52, 239,
     59,  59, 278, 118, 334
), nrow = 3, ncol = 5, byrow = TRUE)


# ranges <- list(
#     c(  0,  60),
#     c( 61, 120),
#     c(121, 180),
#     c(181, 240),
#     c(241, 300),
#     c(301, 360)
# )
breaks <- seq.int(0, 360, 60)


codes <- .bincode(EB, breaks, include.lowest = TRUE)
dim(codes) <- dim(EB)


num.ranges <- apply(codes, 1, function(xx) length(unique(xx)))


I hope this helps!

On Sat, Aug 28, 2021 at 11:57 AM Eliza Botto <eliza_botto at outlook.com>
wrote:

  
  
Message-ID: <CAPcHnpSpJg6ix2Mei9tygGyF4juAM5otOZepYfZEX2N5++R7rw@mail.gmail.com>
In-Reply-To: <AS8P194MB09991D0DA6E6FB9AACFEA4629AC99@AS8P194MB0999.EURP194.PROD.OUTLOOK.COM>