Erin Grand
November 28, 2017
It takes serious TIME to move everyone and everything to code.
dplyr
, %>%
janitor
, tidyr
assertr
Data type | Example |
---|---|
Integer | 1 |
Logical | TRUE |
Numeric | 1.1 |
String / character | "Red" |
Factor (enumerated string) | "Amber" or 2 in c("Red","Amber","Green") |
Complex | i |
Date | 2015-04-24 |
NA | NA |
Besides selecting sets of existing columns, it's often useful to add new columns that are functions of existing columns. That's the job of mutate()
.
library(tidyverse)
library(fivethirtyeight)
avengers <- mutate(fivethirtyeight::avengers,
death1 = if_else(!is.na(death1) & death1, 1, 0 ),
death2 = if_else(!is.na(death2) & death2, 1, 0 ),
death3 = if_else(!is.na(death3) & death3, 1, 0 ),
death4 = if_else(!is.na(death4) & death4, 1, 0 ),
death5 = if_else(!is.na(death5) & death5, 1, 0 ),
total_deaths = death1 + death2 + death3 + death4 + death5)
Task: Create a column called Pass
that describes if the student is predicted to pass the exam (1) or not (0).