I have several datasets, each for a particular time point, and each containing several measures. For each of them, I want to conduct a one-sample t-test on each measure, so across all the columns. Each measure has a different mu value that I want to compare my results with. I have tried creating a function to do this so I only have to give it the name of the dataset as an argument. I have created a list of mu values. However, the function won't accept this and I get an error. Here is an example dataset:
t1 <- rnorm(20, 10, 1)
t2 <- rnorm(20, 10, 1)
t3 <- rnorm(20, 10, 1)
test_data <- data.frame(t1, t2, t3)
And the lists of mu values and variables:
muvals <- c(24, 51.8, 21.89)
varlist <- c(t1, t2, t3)
This is my attempt at the function:
onett <- function(tpoint) {
t.test(tpoint$varlist, mu = muvals)
}
And the error message I get is: Error in t.test.default(tpoint$varlist, mu = muvals) : 'mu' must be a single number
Is there a way to get this function to work, or otherwise iterate through each column and the list of mu values?
Edit: Each mu value only applies to one column. So the first value for the first column, etc.