-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStart up.R
71 lines (57 loc) · 2.36 KB
/
Start up.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Load packages -----------------------------------------------------------
# data manipulation
library(dplyr)
library(tidyr)
# graphing
library(hrbrthemes)
library(ggplot2)
library(ggtext)
# Load data ---------------------------------------------------------------
# needs to be in same folder as project
load("rat_data.Rdata")
# Prep rat data
rat_data = ungroup(rat_data) %>% filter(intensity >= 40) %>%
mutate(player = "Rat")
# build rat_score_table
# Note hard coded based on fastest and slowest rats with complete data
rat_score_table =
filter(rat_data, rat_ID %in% c(15, 20) & intensity %in% c(40, 60, 90)) %>%
select(rat_ID, rat_name, intensity, reaction) %>%
tidyr::spread(intensity, reaction) %>%
# sort so slowest is on bottom
arrange(desc(`40`)) %>% mutate(player = c("Rat (Slowest)", "Rat (Fastest)"), .before = rat_ID) %>%
rename(quiet = `40`, mid = `60`, loud = `90`) %>%
select(-c(rat_ID, rat_name)) %>%
select(player, loud, mid, quiet)
library(data.table)
if (file.exists("human_average.csv")) {
Human_data <- fread("human_average.csv", header = TRUE)
} else {
Human_data <- fread("Human data.csv", header = TRUE) %>% mutate(player = "Human")
fwrite(Human_data, "human_average.csv")
}
# Necessary functions -----------------------------------------------------
Update_human_averages <- function(single_player_data) {
# artificially assign an intensity value
single_player_data =
rename(single_player_data, `40` = quiet, `90` = loud) %>%
# Go from wide to long format
tidyr::gather(key = "intensity", value = "reaction", num_range("", 10:90)) %>%
mutate(intensity = as.numeric(intensity),
player = "Human")
# Add data to averages in memory at bottom of table
Human_data = bind_rows(Human_data, single_player_data)
# pop off new rows (there should be 3) with all necessary columns for
# appending to existing table
new_row = tail(Human_data, n = 2)
# Add new data to saved table
data.table::fwrite(new_row, file = "human_average.csv", append = TRUE)
}
#
#
# # Fake human data ---------------------------------------------------------
#
# scores = tibble(player = c(0, 1, 2, 3),
# quiet = c(150, 200, 210, 189),
# mid = c(140, 132, 138, 178),
# loud = c(110, 125, 132, 112))