0

T.test function works in my Shiny app until I make one of the variables reactive then it returns Error:variable lengths differ (found for 'Group')

output$t_test <- reactive({
                           t_test_result <- t.test(Age ~ Group, data, var.equal = TRUE)
                           print(t_test_result$p.value) })

works

output$t_test <- reactive({
                           t_test_result <- t.test(input$Age ~ Group, data, var.equal = TRUE)
                           print(t_test_result$p.value) })

Returns Error:variable lengths differ (found for 'Group')

I haven't been able to find any posts with this exact issue.

  • Perhaps you can post a [MRE](https://stackoverflow.com/help/minimal-reproducible-example) with some sample data. – YBS Apr 24 '22 at 15:54
  • The one that doesn't work assumes that there is some input with an id named "Age". The problem is that Age will likely be a single or a few values. `t.test()` wants whatever is on the left-hand side of the tilde to be the same length as the variable on the right-hand side of the tilde. That's the nature of the error. – DaveArmstrong Apr 24 '22 at 15:58
  • Try `t.test(data[[input$Age]] ~ Group,...)` – YBS Apr 24 '22 at 16:03

0 Answers0