t-test with two samples

hi i am trying to create a t-Test: Two-Sample Assuming Equal Variances for the pH of Orana and Riverina (like this is excel) using rmarkdown. may i pls be guided to it? thank you!

We really need some sample data and your complete code.

See

Also a handy way to supply sample data is to use the dput() function. See ?dput. If you have a very large data set then something like head(dput(myfile), 100) will likely supply enough data for us to work with.

Based on the layout of variables I can see in your screenshot, I'm going to guess that your data are set up with one column containing pH values from Orana, and one column containing pH values from Riverina. If that's the case, you need to change your tilde (~) to a comma, and identify the variables with the data frame name directly rather than using the data= argument:

t.test(soil$Orana, soil$Riverina)

The construction you used would be the format if you had your data set up with one column indicating the locations of the measurements and one indicating the values, something like this:

location pH
Orana 6.2
Orana 5.9
Riverina 7.1
Riverina 7.3

And then you'd use:

t.test(pH ~ location, data=soil)

1 Like

Hi, thank you for the response. Apologies for the incomplete info. pls see below the result after trying it. The file name is pH and it is a record of pH values between 2 regions: Orana and Riverina. thanks again!

Given the data setup you're showing, the code on line 141 won't work, and that looks to be the source of the error. The code on line 143 should work if run by itself, if your data are actually in the format shown in a data frame called pH. If things still don't work, my guess would be the data aren't in quite the format you think they are in R. You could post the output of a head(pH) command if there's still a problem. I don't think six rows of your data are going to allow anyone to steal your findings, but if you're worried about that you could alter the values before you post them.

A couple of other thoughts:

  • It might be easier to just run this code from the console rather than an R Notebook until you get the bugs worked out.

  • It might be a good idea for code clarity to avoid giving the data frame the same name as one of the variables in it.

1 Like

ok thank you. followed your advice and changed the file name but this time there is an error saying it could not find the function. did i miss to enter a code? may i pls be guided to it? thank you.

apologies this is for boxplot and im creating it before the t-test for two samples.

may i still be guided to it? thank you!

hi already figured out the boxplot. will update re the progress of t-test. thank you!

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.