we found a surprising result from basic code in R. We search for answers online but found nothing.
Does anyone knows the reason of this result?
the following code generates a fake data.frame
z2 <- data.frame(a=rep(1:120,100), b=rep(rep(c(0,1),each=120),50), c=rep(rep(c(0,1),each=240),25), d=rep(rep(seq(.1,2.5,.1),each=120),4)
we want the subset of z2 having d==1.5, but the result is an empty data.frame.
subset(z2,d==1.5) [1] a b c d <0 rows> (or 0-length row.names)
however, the value 1.5 is present in the dataframe
z2[7750,] a b c d 7750 70 0 0 1.5
but simple functions do not work:
table(z2$d==1.5) FALSE 12000
can anyone say what the h*** has happened ? please help, my head has exploded XD
G.M.
Giuseppe Marano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.