smartround(c(1:10,NA),2)
smartround(c(1:10,NA),2,short=TRUE)
smartround(iris[,1:4],7,short=TRUE)
if(require(hflights)){
x <- hflights[,c("ArrDelay")]
xr <- smartround(x, 100)
print(length(unique(xr))) ## 101: 100 and NA
## xr is almost equal to x
print(cor(x,xr,use="pairwise.complete.obs")) # 0.998
## Now, with a 2-dimension data frame
d0 <- hflights[,c("ArrDelay","DepDelay")]
t0 <- tablefreq(d0)
print(nrow(t0)) # there are 11046 distinct cases
## we reduce to just 100 distinct cases
d2 <- smartround(d0,100)
## The correlation is greater than 0.96
print(cor(cbind(d0,d2),use="pairwise.complete.obs"))
print(system.time(t1 <- smartround(d0,100,short=TRUE)))
## this is fast
print(system.time(tfast <- smartround(t0,100,freq=~freq, short=TRUE)))
print(all.equal(t1,tfast))
print(nrow(t1))
}
Run the code above in your browser using DataLab