I know tapply can be used to separate groups and calculate means individually. I was wondering if there is a function to isolate one of these means for separate analysis.
I am comparing my collected data to the class means using a One sample t-test. Here a sample of the data I'm using
#Sample of my data
structure(list(
pKa = c(6.946, 7.1, 6.625, 7.528, 7.102, 6.743,6.936, 6.579, 6.672, 7.27),
pH = c("pH_6.1", "pH_6.7", "pH_7.3", "pH_8.1", "pH_6.1", "pH_6.7", "pH_7.3", "pH_8.1", "pH_6.1", "pH_6.7"),
id = c("XAU", "XAU", "XAU", "XAU", "MyData", "MyData", "MyData","MyData", "PQ", "PQ")),
row.names = c(NA, 10L), class = "data.frame")
I'm trying to extract the means of each "pKa"(response variable) grouped by "pH" (explanatory variable), and use each mean in a t-test to compare 'MyData' Vs the total collected Class data. Below shows the data I want to compare (Mydata Vs the class means at different pH groups: 6.1, 6.7, 7.3, 8.1)
# The data I collected
Exp2MyData
#pKa pH id
#5 7.102 pH_6.1 MyData
#6 6.743 pH_6.7 MyData
#7 6.936 pH_7.3 MyData
#8 6.579 pH_8.1 MyData
#Means of the class data
E2 <- tapply(Exp2$pKa, Exp2$pH, mean)
E2
#pH_6.1 pH_6.7 pH_7.3 pH_8.1
# 7.102 6.743 6.936 6.579
The T-test code I am trying to use, to see whether my collected data is significantly different from the class', is:
t.test(mean of whole class pKa for 'X'pH, pKa value I collected)
This is code I am currently trying to use
#Making pH 8.1 into seperatate group
Buff_8.1 <- subset(Exp2,pH=="pH_8.1")
#Obtaining the means for pKa @ pH = 8.1
m8.1 <- mean(Buff_8.1$pKa)
m8.1
#t.test
t.test(m8.1, mu= 6.579)
But I get the error "Error in t.test.default(m8.1, mu = 6.579) : not enough 'x' observations"
Any help would be wonderful.