[R] cut{base}: is it a bug?

Jose Claudio Faria jo@ecl@udio@f@ri@ @ending from gm@il@com
Mon Sep 24 16:32:19 CEST 2018


Dears members,

Is the below a bug of the cut {base} function?

dat <- c(
 0.6, 0.6, 0.6, 0.7, 0.7, 0.7, 0.7, 0.7, #(8)
 0.8, 0.8, 0.8, 0.9, 0.9, 0.9, 0.9,        #(7)
 1.0, 1.0, 1.0, 1.0, 1.1, 1.1, 1.1,        #(7)
 1.2, 1.2, 1.2, 1.2, 1.3, 1.3, 1.3,        #(7)
 1.4, 1.4, 1.4, 1.5, 1.5, 1.5,               #(6)
 1.6, 1.6, 1.7, 1.7, 1.7, 1.7,               #(6)
 1.8, 1.8, 1.8, 1.9, 1.9,                      #(5)
 2.0, 2.0, 2.0, 2.0, 2.0, 2.1                #(6)
 )

# making class from function "cut"
(f <- cut(dat,
          breaks= seq(from=.6, to=2.2, by=.2),
          include.lowest=TRUE,
          dig.lab=10L,
          right=FALSE))

# more easy to see the table
as.matrix(tb <- table(f))

# Checking
print(length(dat[dat >= 0.6 & dat < 0.8])) == tb[1]
print(length(dat[dat >= 0.8 & dat < 1.0])) == tb[2]
print(length(dat[dat >= 1.0 & dat < 1.2])) == tb[3]  # !?
print(length(dat[dat >= 1.2 & dat < 1.4])) == tb[4]  # !?
print(length(dat[dat >= 1.4 & dat < 1.6])) == tb[5]
print(length(dat[dat >= 1.6 & dat < 1.8])) == tb[6]  # !?
print(length(dat[dat >= 1.8 & dat < 2.0])) == tb[7]  # !?
print(length(dat[dat >= 2.0 & dat < 2.2])) == tb[8]

Best,
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
Jose Claudio Faria
UESC/DCET/Brasil
joseclaudio.faria at gmail.com
Telefones:
55(73)3680.5545 - UESC
55(73)99966.9100 - VIVO
55(73)98817.6159 - OI
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\

If you have software to deal with statistics, you have arms;
if you have good software, you have arms and legs;
if you have software like R, you have arms, legs and wings...
the height of your flight depends only on you!

	[[alternative HTML version deleted]]



More information about the R-help mailing list