Home > other >  match.arg(alternative) error appearing while trying to carry out t-test - R
match.arg(alternative) error appearing while trying to carry out t-test - R

Time:03-09

Hello everyone :) I'm quite new to R so having quite a few difficulties atm but after trying to do a t-test I'm getting this error:

Error in match.arg(alternative) : 'arg' must be NULL or a character vector

This is the code I've used:

data %>%
  t.test(mean_resp_rew, condition, data = data)
data

and I'm very unsure as to what is going wrong.

Edit (not sure if this is the right way of giving reproducible data haha) the df is called data:

data sample: df sample

data_summary: data_summary

CodePudding user response:

The pipe x %>% foo(y) is interpreted as foo(x, y). So your code is interpreted as t.test(data, mean_resp_rew, condition, data = data), with the data argument first and last. Looking at the ?t.test help page, if you use a data argument it expects a formula, so we could try this:

df %>% t.test(mean_resp_rew ~ condition, data = .)

Which should work assuming mean_resp_rew and condition are columns in your df data frame (and that condition has 2 unique values). There's no nesting, so we don't gain anything from the pipe in this case, so I would recommend keeping it simple with

t.test(mean_resp_rew ~ condition, data = df)
  • Related