0
dat <- structure(list(missing = c(2166541L, 2166541L, 2166541L, 2166541L, 2166541L, 2166541L, 2166541L), 
           full = c(2166530L, 2166531L, 2120278L, 2166532L, 2166529L, 2166528L, 2120277L), 
           weight = c(0.682281314251013, 0.178850991915291, 0.0294579547230352, 0.0277997025189748, 0.0426425821406883, 0.0277997025189748, 0.0111677519320228)), 
      class = "data.frame", row.names = c(NA, -7L))

sum(dat$weight) # weights add up to 1
q.vec <- unique(dat$missing)

for(q in seq_along(q.vec)){

  id <- q.vec[q]

  sub.dat <- dat %>% dplyr::filter(missing == id)
  print(sum(sub.dat$weight))
  if(sum(sub.dat$weight) != 1) { print(id)}
}

I am not able to figure out why print(id) is getting run in the above loop even though sum(sub.dat$weight) != 1 condition is not met.

89_Simple
  • 3,393
  • 3
  • 39
  • 94

0 Answers0