0

I'm kind of ignorant on the topic so it might be a simple mistake, but I have used cutpoints and then i'm trying to print a table with the sum of elements in each bracket, but one has zero in it and it just disappears. I've seen similar problems solved with "factor", but I don't know how to make it work with cutpoints. This is the full code:

nrep<-100000
lambda<-1/6
m<-1/lambda
set.seed(229985)
x<-rexp(nrep,1/m)
brk<-seq(0,80,8)
xx <- cutpoints(x,brk, destra = TRUE)
#
c(mean(x),m)
c(var(x),m^2)
c(median(x),m*log(2))
c(min(x),max(x))
#
fo<-table(xx)
sum(fo)
fo
#
p<-pexp(brk,lambda)
fa<-diff(p)*nrep
sum(fa)
cbind(fo,round(fa,1))
chi2(fo,fa)

Thank you in advance, Riccardo

  • 2
    It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Where does the `cutpoints` function come from? That does not appear to be a base R function. – MrFlick May 06 '22 at 16:30
  • 1
    Welcome to Stackoverflow. What is your `m` and `nrep`? – Chris May 06 '22 at 16:34
  • 2
    ... What is `nrep`? What is `cutpoints`? – r2evans May 06 '22 at 16:36
  • m and nrep are just variables... i defined them on top of the document but forgot to copy that part. They are 1/6 and 100000. I don't exactly know how cutpoints works 'cause it's what our professor has told us to use for this kind of stuff... it creates classes if I'm not mistaken. – Riccardo Zanoni May 07 '22 at 08:22
  • Basically the problem arises when i try to use cbind, 'cause the two vectors have different length due to the missing class with count=0 – Riccardo Zanoni May 07 '22 at 08:25
  • Which package do you use for `cutpoint`? – Julian May 07 '22 at 08:27

0 Answers0