Thread for Gov 1005/1006 Students to Submit a Practice Reprex

males <- replicate(16, "M")
females <- replicate(18,"F")
class <-c(males,females)

Created on 2020-02-12 by the reprex package (v0.3.0)

library(tidyverse)

library(moderndive)


class <- tibble(id=1:32) %>%
  mutate(gender = ifelse(id < 15, 0, 1)) %>%
  select(gender)


  sample <- rep_sample_n(class, size = 32, replace = FALSE, reps = 1000) %>%
    group_by(replicate) %>%
    mutate(table = rep(1:8, each = 4)) %>%
    group_by(table, replicate) %>%
    summarize(total = sum(gender)) %>%
    mutate(homogenous = ifelse((total == 0 | total == 4), 1, 0))
  
  sample2 <- sample %>%
    group_by(replicate) %>%
    summarize(homogenous_per_class = sum(homogenous))

Created on 2020-02-12 by the reprex package (v0.3.0)

library(infer)
library(reprex)
library(tidyverse)

#1 is female 
students <- tibble(female = rep(0:1, 15))

sample <- students %>% 
  rep_sample_n(size = 4, reps = 8) %>% 
  group_by(replicate) %>% 
  summarize(table = sum(female))

Created on 2020-02-12 by the reprex package (v0.3.0)

I created one sample of the tables, now what?

tables <- data.frame(gender = sample(x, 32),
                     table = rep(class, 4)) %>% 
  group_by(table) %>% 
  summarize(num_women = sum(gender)) %>% 
  mutate(clumps = ifelse(num_women%in% c(0,4), yes = 1, no = 0)) %>% 
  summarise(prop_clumps = mean(clumps))
#> Error in data.frame(gender = sample(x, 32), table = rep(class, 4)) %>% : could not find function "%>%"

Created on 2020-02-12 by the reprex package (v0.3.0)

students <- data.frame(number = c(rep(1:8, 4)),
                       gender = sample(c(rep(1, 16), rep(0, 16)))) %>% 
  group_by(number) %>% 
  summarize(table = sum(gender)) %>% 
  mutate(clumped = ifelse(table %in% c(0, 4), 1, 0)) %>% 
  summarize(prop_clumped = mean(clumped))
#> Error in data.frame(number = c(rep(1:8, 4)), gender = sample(c(rep(1, : could not find function "%>%"

Created on 2020-02-12 by the reprex package (v0.3.0)

list <- c(rep(1,16), rep(0,14))

Created on 2020-02-12 by the reprex package (v0.3.0)

#trying to add column name "gender"
students <- c(rep("m", 14), rep("f",16))
tables <- c(rep(c(1:7), 4), c(8, 8)) 
class <-as.data.frame(cbind.data.frame(tables, students)) 

#created a single
simulation <- function(data) {
  seats <- nrow(class)
  boot <- class$students %>% 
    sample(seats, replace = FALSE)
  
}
# do it 100 times 
output <- rep(100, simulation)
#> Error in eval(expr, envir, enclos): cannot coerce type 'closure' to vector of type 'double'
#> Error in eval(expr, envir, enclos): cannot coerce type 'closure' to vector of type 'double'

Created on 2020-02-12 by the reprex package (v0.3.0)

for (q in 1:reps) {
 
compositions[q] <- data.frame(gender = sample(x, 30),
                     table = c(rep(class_1, 4), 8,8)) %>% 
  group_by(table) %>% 
  summarize(num_women = sum(gender)) %>% 
  mutate(clumps = ifelse(num_women %in% c(0,4), yes = 1, no = 0)) %>% 
  summarise(prop_clumps = mean(clumps))
}
#> Error in eval(expr, envir, enclos): object 'reps' not found

Created on 2020-02-12 by the reprex package (v0.3.0)

image

class30 <- c(rep("M", 16), rep("F", 14))

Created on 2020-02-12 by the reprex package (v0.3.0)

dat <- c(rep(0, 12), rep(1, 12)) %>% tibble()
#> Error in c(rep(0, 12), rep(1, 12)) %>% tibble(): could not find function "%>%"

Created on 2020-02-12 by the reprex package (v0.3.0)

num_M = 18
num_F = 18
table_size = 4

sample_no <- 1000
test_results <- c()
for (i in 1:sample_no) {
  test_results <- test_results %>% 
    append(sample_average_clumps(num_M, num_F, table_size))
}
#> Error in test_results %>% append(sample_average_clumps(num_M, num_F, table_size)): could not find function "%>%"

Created on 2020-02-12 by the reprex package (v0.3.0)

class %>% sample(value, 29, replace = FALSE)
#> Error in class %>% sample(value, 29, replace = FALSE): could not find function "%>%"

males = replicate(14, "m")
females = replicate(16, "f")
class <- c(males, females)

x <- read_excel(file = "class_enrollment_summary_by_term2.18.20.xlsx")
#> Error in read_excel(file = "class_enrollment_summary_by_term2.18.20.xlsx"): could not find function "read_excel"

Created on 2020-02-18 by the reprex package (v0.3.0)

x <- read_excel(file = "class_enrollment_summary_by_term2.8.20.xlsx", 
    skip = 3)
#> Error in read_excel(file = "class_enrollment_summary_by_term2.8.20.xlsx", : could not find function "read_excel"

Created on 2020-02-18 by the reprex package (v0.3.0)

Why isn't this working?

enrollment %>% 
  glimpse()
#> Error in enrollment %>% glimpse(): could not find function "%>%"

Created on 2020-02-18 by the reprex package (v0.3.0)

class_enrollment_summary_by_term2.18.20.xlsx
#> Error in eval(expr, envir, enclos): object 'class_enrollment_summary_by_term2.18.20.xlsx' not found

Is "mode" not a command in R?

mode(4, 5, 6, 7, 7, 8, 8, 9)
#> Error in mode(4, 5, 6, 7, 7, 8, 8, 9): unused arguments (5, 6, 7, 7, 8, 8, 9)