# let's create vector with mean 3 and standard deviation 1 # normally distributed in interval 0-5 # 100 observations set.seed(123) x <- rnorm(100, mean = 3, sd = 1) hist(x, breaks = 20, col = "lightblue", main = "Histogram of x", xlab = "x") # now let's make for loop to create 24*100 observations # and store them in 24 vectors a - x # each vector will have different mean, starting from 0.5 and going up by 0.1 for (i in 1:24) { assign(paste0("a", letters[i]), rnorm(100, mean = 0.5 + 0.2*i, sd = 1)) } hist(aw, breaks = 20, col = "lightblue", main = "Histogram of aw", xlab = "aw") # now let's put all the vectors into one data frame # variable condition will be the name of the vector # and variable value will be the value of the vector df <- data.frame() for (i in 1:24) { df <- rbind(df, data.frame(condition = paste0("a", letters[i]), value = get(paste0("a", letters[i])))) } # let's add x as a condition to the data frame df <- rbind(df, data.frame(condition = "x", value = x)) # now let's make a boxplot boxplot(value ~ condition, data = df, col = "lightblue", main = "Boxplot of x and aw", xlab = "condition", ylab = "value") # let's make histogram of two conditions: aa and x from df # first tidyverse to subset df to only x and aa library(tidyverse) df2 <- df %>% filter(condition %in% c("x", "aa")) library(ggplot2) ggplot(df2, aes(x = value, fill = condition)) + geom_histogram(bins = 20, alpha = 0.5, position = "identity") + labs(title = "Histogram of x and aa", x = "value", y = "count") + theme_minimal() # let's compute t.test for x and aa t.test(x, aa, alternative = "two.sided") # let's load csv of student's names, semicolon separated students <- read.csv("seznam_export.csv", sep = ";") # add column condition to students data frame # and fill it from ab to az # but in reverse order students$condition <- paste0("a", letters[26:6]) # students$condition <- sample(c("x", "aa"), nrow(students), replace = TRUE) # students$condition <- paste0("a", letters[1:nrow(students)]) print(students) write.csv(students, "students.csv", row.names = FALSE)