###################################################################
############### Module 6, Basics of data wrangling ################
###################################################################
## Lesson 10: Introduction to data wrangling: or how to do things with your data


###################################
##### INTRODUCTION TO PACKAGES

library("tidyverse")

avian_raw_data <- read.csv("data/avian_mating_data_raw.csv")

avian_raw_data[,c(2,3)]

###################################
##### TIBBLES: THE BETTER DATAFRAME

avian_data_raw <- as_tibble(avian_raw_data)
avian_raw_data <- read_csv("data/avian_mating_data_raw.csv")

###################################
#####  SELECT AND FILTER

avian_raw_data[,c(2,3)]

avian_mass_data <- select(avian_raw_data, Family, `Species number`, M_mass, 
                          M_mass_N, F_mass, F_mass_N)

avian_data_nomass <- select(avian_raw_data, -M_mass, -M_mass_N, -F_mass, -F_mass_N)

avian_mass_data <- select(avian_raw_data, Family, species_name = `Species name`, 
                          M_mass, M_mass_N, F_mass, F_mass_N)

names(avian_raw_data)

avian_mass_small <- filter(avian_mass_data, M_mass < 100, M_mass > 0)

is_it_Lamprotornis <- grepl("Lamprotornis", avian_mass_small$species_name)

sum(is_it_Lamprotornis)

small_Lamprotornis <- filter(avian_mass_small, grepl("Lamprotornis", species_name))


###################################
##### SUMMARY
# - what are packages?
# - what are tibbles? better dataframes
# - select and filter functions for subsetting your data

# In the next one we will go over how to begin manipulating and modifying
# your data.
