0

I am trying to construct a t.test using a Hi/Lo method. But I am getting an error, this is my code:

##hi/lo version 
dat = read.csv("parking.csv", comment.char = "#", as.is = TRUE)


dat = dat[dat$prepost!="" & !is.na(dat$viol_pc) , ];
dat = dat[, c("wbcode","country","viol_pc", "prepost","corruption")]


dat$hilo = ifelse(dat$corruption > 0.33, "hi", "lo")


pp_hilo = t.test(dat$hilo[dat$prepost=="pre"], dat$hilo[dat$prepost=="pos"])

The error I get is

Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") : missing value where TRUE/FALSE needed

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
NoHam
  • 1
  • Please edit as shown [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – NelsonGon Mar 26 '20 at 13:31
  • 3
    dat$hilo = ifelse(dat$corruption > 0.33, "hi", "lo") : This makes dat$hilo a character / factor. You are doing a t.test on factors.. this is not correct. Is there a typo somewhere? Which column are u supposed to test? – StupidWolf Mar 26 '20 at 13:41

0 Answers0