Bloop
Bloop

Reputation: 73

How do I change standard deviation to 2SD in R?

This is my current code:

library(rstatix)
library(dplyr)

lk %>%
  group_by(sample) %>%
  get_summary_stats(cd, type = "mean_sd")
lk %>% anova_test(cd ~ sample)

it prints the mean and 1 standard deviation, but I would like it to print 2 standard deviation instead. Apart from manually multiplying the 1 standard deviation, is there a way to code it? Cause I'm using this code multiple times.

Upvotes: 0

Views: 171

Answers (1)

SAL
SAL

Reputation: 2140

You can calculate 2sd by adding mutate() function to your code after get_summary_stats() function:

library(tidyverse)
library(rstatix)

lk %>%
  group_by(sample) %>%
  get_summary_stats(cd, type = "mean_sd") %>%
  mutate(sd = 2 * sd) 

lk %>% anova_test(cd ~ sample)

Upvotes: 3

Related Questions