Likely you have NA's that contribute to length.
> x = c(1, NA)
> x[x==1]
[1] 1 NA
Use cut
rather than ifelse
(the default without the labels=
argument is better).
set.seed(123); x = c(runif(10, -1, 2), NA)
y = cut(x, c(-Inf, seq(0, .75, .25), Inf),
labels=c("void", "0-0.25", "0.25-0.5", "0.5-0.75", ">0.75"))
leading to
> y
[1] void >0.75 0-0.25 >0.75 >0.75 void 0.5-0.75 >0.75
[9] 0.5-0.75 0.25-0.5 <NA>
Levels: void 0-0.25 0.25-0.5 0.5-0.75 >0.75
Use table
to summarize the data.
> table(y)
y
void 0-0.25 0.25-0.5 0.5-0.75 >0.75
2 1 1 2 4
> table(y, useNA="ifany")
y
void 0-0.25 0.25-0.5 0.5-0.75 >0.75 <NA>
2 1 1 2 4 1
text
is vectorized.
text(1:4, 1.07, table(y)[2:5])
Complete solution (tested by rg255)
data$SimDeltaClass <- cut(data$SimDelta, c(-Inf, seq(0, .75, .25), Inf),
labels=c("void", "0-0.25", "0.25-0.5", "0.5-0.75", ">0.75"))
text(x=1:4, y=1.07, table(data$SimDeltaClass[fdr])[2:5], cex=0.8, col="black")