Search code examples
rcut

Error in setting bin grouping using cut Error in if (d2 == 0L) { : missing value where TRUE/FALSE needed


I try to group my dataset to different bin size with the function cut,

cuts <- apply(rd, 4, cut, c(-Inf, seq(10, 80, 10), Inf), labels=10:90)

but this error pops out:

Error in if (d2 == 0L) { : missing value where TRUE/FALSE needed

I guess it's because some of my value just matches the cutoff value, can anyone please teach me how to modify my code so that if it matches it will go to the group >= the value??


Solution

  • If we are using cut on the 4th column

    cut(rd[,4], breaks= c(-Inf, seq(10, 80, 10), Inf), labels=10:90)
    

    The apply methods are used for matrices with > one dimension. Here, we are only using the 4th column, so the function can be directly applied on the vector.