Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Here is my code and below is the error that I'm getting:

t.test(replication$Expecatation_Factor, replication$Amused_After_centered)
#replication$Expecatation_Factor is a factor as verified by str() and class()
#replication$Amused_After_centered is an integer as verified by srt() and class()

ERROR REPORTED

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) :   Calling var(x) on a factor x is deprecated and will
become an error.   Use something like 'all(duplicated(x)[-1L])' to
test for a constant vector.
                What are you trying to do with that factor? When calling t.test() like that, it expects two numeric values. Did you mean to use the formula syntax for groups? Like t.test(Amused_After_centered~Expecatation_Factor, data=replication)?
– MrFlick
                Jan 9, 2019 at 21:03

Without seeing your actual dataset it's hard to say exactly what's happening, but it appears that one of the vectors you're using is not actually numeric. See below for what happens when you try to use t.test on a string variable; it's very close to your warning.

> t.test(factor(c('a', 'b', 'c')), c(1, 2, 3)) # you can't run a t-test on c('a', 'b', 'c')
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) :
  Calling var(x) on a factor x is deprecated and will become an error.
  Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.