[R] missing value where TRUE/FALSE needed
Peter Lauren
peterdlauren at yahoo.com
Tue Jun 13 21:19:42 CEST 2006
I am using R 2.3.0 and trying to run the following
code.
BinCnt=round(ShorterVectorLength/10)
BinMatrix=matrix(nrow=BinCnt, ncol=2)
Increment=(VectorRange[2]-VectorRange[1])/BinCnt
BinMatrix[1,1]=VectorRange[1]
BinMatrix[1,2]=VectorRange[1]+Increment
for (i in 2:BinCnt)
{
BinMatrix[i,1]=BinMatrix[i-1,2]
BinMatrix[i,2]=BinMatrix[i,2]+Increment
}
# Count entries in each bin
Histogram=vector(length=BinCnt, mode="numeric")
for (i in 1:BinCnt) Histogram[i]=0
VectorLength=length(FormerVector)
for (i in 1:VectorLength)
{
Value=FormerVector[i]
for (j in 1:BinCnt) if (Value>=BinMatrix[j,1] &&
Value<=BinMatrix[j,2])
{
Histogram[j]=Histogram[j]+1
break;
}
}
Unfotunately, at
if (Value>=BinMatrix[j,1] && Value<=BinMatrix[j,2])
I get the following error message
Error in if (Value >= BinMatrix[j, 1] && Value <=
BinMatrix[j, 2]) { :
missing value where TRUE/FALSE needed
I inserted browser() just before the call and
(Value>=BinMatrix[j,1] && Value<=BinMatrix[j,2])
returned FALSE.
Is there a bug in my code or a bug in my version of R?
Many thanks in advance,
Peter.
More information about the R-help
mailing list