Mean_SD_Table.R Tutorial - sciencesharon/MicrobialSeq GitHub Wiki
Mean_SD_Table.R Tutorial
Mean ± Standard Deviation Table
Have you ever wanted to make a nice little mean ± standard deviation table of numerical data for publication?
Perhaps one that looks a little like this?
Then this is the script for you!
Example Data Input
How to use the script
Step 1: Load the data into R
data <- read.csv("/path/to/your/data/Example_Data_Table.csv")
Step 2: Separate and list the groups to compare
Male <- data[data$Gender %in% c("Male"),]
Female <- data[data$Gender %in% c("Female"),]
data_list <- list(Male = Male, Female = Female)
Step 3: Set the numerical columns which will be compared between the groups
columns <- colnames(data)[1:10]
Step 4: Set your output directory
dir <- ("/path/to/save/your/output")
Step 5: Utilize the function
means <- calculate_mean_sd(data_list = data_list, columns= columns, file_name = "mean_SD.csv", directory = dir, decimal_places = 2, statistical_test = "ttest", p_adjust_method = "BH", stars = TRUE)
Options in the function are as follows:
-
data_list: this is the data input
-
columns: these are the column names of numerical columns you wish to summarize and compare between the groups
-
file_name: this is the output .csv file name
-
directory: path to save the file
-
decimal_places: this is the number of decimals to round the output
-
statistical_test: default is NULL, can either be set to "ttest" or "wilcox" to perform t-test or Wilcox Rank Sum Test
-
p_adjust_method: default is NULL, can either be set to "bonferroni" or "BH" to adjust p_value
-
stars: default is FALSE, if TRUE will output "stars" column with * = 0.05, ** = 0.005, *** = 0.0005, **** = 0.00005, and ***** = 0.000005
Example Output
This can easily be made into a pretty table with minor formatting :)
Like this: