dimanche 22 septembre 2019

R : How to optimize OR condition with intervals?

I have

x=c(601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614,
 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630,
 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646,
 647, 648, 649, 650)

I would like to test if x is equal to the interval (1:50) or (51:100) or (101:150) or (151:200) .... or (951:1000).

I wrote this code :

(
    x == c(1:50) || 
    x == c(51:100) ||
    x == c(101:150) ||
    x == c(151:200) ||
    x == c(201:250) ||
    x == c(251:300) ||
    x == c(301:350) || 
    x == c(351:400) ||
    x == c(401:450) ||
    x == c(451:500) ||
    x == c(501:550) ||
    x == c(551:600) ||
    x == c(601:650) ||
    x == c(651:700) || 
    x == c(701:750) ||
    x == c(751:800) ||
    x == c(801:850) ||
    x == c(851:900) ||
    x == c(901:950) || 
    x == c(951:1000)
)

I don't know how to optimize it?

Aucun commentaire:

Enregistrer un commentaire