# Sample data frame with 3 columns
data <- data.frame(
Math = c(78, 75, 82, 70, 88, 92, 85, 80, 76, 81),
Science = c(85, 88, 80, 78, 92, 86, 89, 91, 87, 84),
English = c(72, 74, 76, 71, 75, 79, 73, 77, 80, 78)
)
# Display the data frame
print(data)
# Applying one-sample t-test to all columns
t_test_results <- sapply(data, function(column) {
test_result <- t.test(column, mu = 75)
return(c(
Mean = mean(column),
t_value = test_result$statistic,
p_value = test_result$p.value,
conf_low = test_result$conf.int[1],
conf_high = test_result$conf.int[2]
))
})
# Display the results in a readable format
t_test_results <- as.data.frame(t(t_test_results))
print(t_test_results)