I need to know if one variable is independent of another variable. They are both nominal categories. I have tried a t.test, but this occurs:

t.test(role ~ sr_qual, data = dfsleep)
Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(x) : argument is not numeric or logical: returning NA
2: In var(x) : NAs introduced by coercion
3: In mean.default(y) : argument is not numeric or logical: returning NA
4: In var(y) : NAs introduced by coercion

I need to know if one variable is independent of another variable. They are both nominal categories. I have tried a t.test, but this occurs:

t.test(role ~ sr_qual, data = dfsleep)
Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(x) : argument is not numeric or logical: returning NA
2: In var(x) : NAs introduced by coercion
3: In mean.default(y) : argument is not numeric or logical: returning NA
4: In var(y) : NAs introduced by coercion