non-numeric argument to binary operator: t.test

Hello,
I'm new to using R and am trying to run a two-sided t test.
I have successfully done this with data using whole numbers which I exported in from excel using readxl.
However, I am now trying to do it with data using numbers with decimal places.
I'm trying to run:

t.test(After,Before,mu=0,alt="two-sided",paired=T,conf.level=0.95)
But I'm getting:Error in x - y : non-numeric argument to binary operator
Can anyone help with how to fix this? I've tried converting the cells in my excel spreadsheet to number format and re-importing the data but I'm still getting the error code.
Any help would be much appreciated!

See the FAQ: How to do a minimal reproducible example reprex for beginners to get a more specific answer.

t.test is not restricted to integer vectors: see the help(t.test) example:

## Classical example: Student's sleep data
plot(extra ~ group, data = sleep)

## Traditional interface
with(sleep, t.test(extra[group == 1], extra[group == 2]))
#> 
#>  Welch Two Sample t-test
#> 
#> data:  extra[group == 1] and extra[group == 2]
#> t = -1.8608, df = 17.776, p-value = 0.07939
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  -3.3654832  0.2054832
#> sample estimates:
#> mean of x mean of y 
#>      0.75      2.33

Thanks so much for your reply.
I tried a simpler approach first and just tried retyping the numbers in the excel spreadsheet in two decimal place format and re-importing - this worked!
Thanks again - I have noted that process for the future.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.