# R for Psychological Research, Lesson 5: Pick rows & columns
# Code from the lesson page, in order. Run it line by line with Ctrl+Enter (Cmd+Enter on a Mac).
# Lines that start with # are comments: R ignores them.


# ---- Set up ----

library(tidyverse)
students <- read_csv("data/students.csv", show_col_types = FALSE)


# ---- select(): columns ----

students %>% select(ID, Gender, ExamScore)


# ---- filter(): rows ----

students %>%
  filter(Gender == "Female") %>%
  select(ID, Gender, ExamScore)

students %>% filter(Age >= 25, ExamScore > 80)
students %>% filter(Grade %in% c("A", "B")) %>% nrow()


# ---- arrange(): sort ----

students %>%
  arrange(desc(ExamScore)) %>%
  select(ID, StudyHours, ExamScore) %>%
  head(5)
