Skip to content
Prev 308262 / 398506 Next

cut2 error

Hi Charles,
Sorry, now I remember that I was working with another cut2() function (from Rui's solution) when I tried your data.

dat1<-structure(list(var1 = c(97, 97, 98, 98, 97, 99, 97,
98, 99, 98, 99, 98, 98, 97, 97, 98, 99, 98, 96, 98, 98, 99, 98,
98, 99, 99, 98, 99, 98, 99, 99, 99, 99, 98, 99, 96, 99, 98, 98,
99, 97, 98, 99, 99, 97, 99, 99, 98, 98, 98, 99, NA, 99, 98, 98,
98, 98, 98, 98, 98, 99, 99, 98, 99, 99, 98, 98, 99, 99, 97, 98,
98, 98, 99, 98, 98, 98, 99, 98, 98)), .Names = "var1", row.names = c(NA,
80L), class = "data.frame")
unique(dat1[,1])
#[1] 97 98 99 96 NA
cut2 <- function(x, g = 0){
??? cut(x, breaks = c(-Inf, seq(min(x), max(x), length.out = g)))
}

dat2<-dat1[!is.na(dat1)]
cut2(dat2,g=4)

A.K.