Chapter 8 Bat roost exercise

First we will look at the file bat_roosts.csv. This contains information on the max number of roosts for different Bat species in different UK regions.
The data is from: "Bat Conservation Trust 2020. Roost Count peak counts summary data". Available from https://www.bats.org.uk/our-work/national-bat-monitoring-programme/reports/nbmp-annual-report
Solutions are in the expandable boxes. Try your best to solve each challenge but use the solutions for help if you would like. Even if your method works it can be good to check the solution as there are many ways to do the same thing in R
8.1 Bat roost challenges
Bat roost challenge 1

Read in the file "bat_roosts.csv" as a data frame variable called "bat_df". Ensure the row names contain the Regions (Channel Islands, East Midlands, etc.).
Bat roost challenge 2

Inspect the variable and ensure there are only numerics within the data frame with all strings only being in column and row names.
Bat roost challenge 4

Add a column to "bat_df" called "All_Bat_Species" that contains the totals for each Region.
8.2 Bat roost MCQs

Fantastic! I hope those challenges were engaging and improved your experience working with files and data frames.
Attempt the following MCQs using your final "bat_t_df" object.
- Which region has no roosts?
- Which region has the largest amount of Myotis brandtii roosts (excluding UK)?
- Which Bat species has the highest number of roosts across the UK?
- Which Bat species has the lowest number of roosts across the UK?
You can figure out the MCQs by viewing the data frame. However, you can also figure them out with R code. Below are commands to get the answers for the MCQs. I will let you decipher them yourself.
#Question 1: Which region has no roosts?
col_names_logical_vec <- bat_t_df["All_Bat_Species",] == 0
colnames(bat_t_df)[col_names_logical_vec]
#Question 2: Which region has the largest amount of Myotis brandtii roosts?
species <- "Myotis brandtii"
df_wo_total_species_and_uk <- bat_t_df[
1:(nrow(bat_t_df)-1),1:(ncol(bat_t_df)-1)]
max_colonies <- max(df_wo_total_species_and_uk[species,])
col_names_logical_vec <- df_wo_total_species_and_uk[species,] == max_colonies
colnames(df_wo_total_species_and_uk)[col_names_logical_vec]