-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomassignment.R
More file actions
29 lines (22 loc) · 1.09 KB
/
randomassignment.R
File metadata and controls
29 lines (22 loc) · 1.09 KB
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
# Define the levels for each factor
factor1 <- c('firefox', 'chrome', 'edge')
factor2 <- c('duckduckgo', 'google', 'bing')
# Create the combination of all possible treatments
treatments <- expand.grid(factor1 = factor1, factor2 = factor2)
# Set the number of replications per treatment
replications <- 4
# Create an empty dataframe to store the randomized assignments
randomized_assignments <- data.frame(factor1 = character(),
factor2 = character())
# Perform random assignment for each treatment and replication
for (i in 1:nrow(treatments)) {
for (j in 1:replications) {
randomized_assignments <- rbind(randomized_assignments,
data.frame(factor1 = treatments[i, 'factor1'],
factor2 = treatments[i, 'factor2']))
}
}
# Randomize the assignment order
randomized_assignments <- randomized_assignments[sample(nrow(randomized_assignments)), ]
# Write the factor1 and factor2 columns to the "order.csv" file
write.csv(randomized_assignments, "order.csv", row.names = FALSE,quote = FALSE)