1

I have a problem with my code in R. For this input (and AFAIK only this input), the dimension of my array matrixForSums is different that it's supposed to be. It's supposed to be 113, but instead, the dimensions are 112. If I print sizeForBeta, it's 113 but if I print dim(matrixForSums), it's 112.

Funny thing is, if I choose any other input, it's exactly the dimension it's supposed to be. If sizeForBeta is 130, then dim(matrixForSums) is 130.

Can you help me identify the problem?

    rowNumber<-1
    startIntervalForBeta<- -0.051
    stopIntervalForBeta<-0.062
    movementSizeForBeta<-0.001
    sizeForBeta<-0
    differenceForBeta <- startIntervalForBeta
    sizeForBeta<-(stopIntervalForBeta-startIntervalForBeta)/movementSizeForBeta
    beta0<-array(dim=c(sizeForBeta))
    my_range <- 0:(sizeForBeta)
    for(i in my_range) { 
      beta0[i]<- differenceForBeta
      differenceForBeta<- differenceForBeta+movementSizeForBeta
    }
    matrixForSums= array(0, dim=c(sizeForBeta))
  • This is really interesting. I never noticed this. I found [this post](https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal) is very useful which should also answer your question. – OceanSky_U Feb 13 '21 at 18:56

1 Answers1

0

In fact, you think that it's 113, but it could be that it's 112,99999999999999 .. and R show you 113. So just check it :

floor(sizeForBeta)

[1] 112