Example: what information can you get regarding Templin as the receiver.location on the latest date
library(tidyverse)
#transport_data <- read_csv("data/transport-data.csv")
transport_data %>%
select(sender.location,receiver.location) %>%
unique() # unique sender and receiver locations
# it looks like a city called Templin is a popular receiver location. Let's filter this location
transport_data %>%
filter(receiver.location=="DEU, Templin")
# what is the most recent date for Templin
transport_data %>%
select(date) %>%
.[[1]] %>%
max() # this code shows that the condition of max date exists
[1] "1989-08-23"
# add this condition to the filter
transport_data %>%
filter(receiver.location=="DEU, Templin" & date == max(date)) # return zero rows
# this is because the condition of the max date is set to all the data not just the data for Templin.
#to solve the problem, we need to have multiple fiters applied
transport_data %>%
filter(receiver.location== "DEU, Templin") %>%
filter(date == max(date))
Apart from select the column names, what else can you do with select statements?
# select statement
# select columns with word "receive" in it
transport_data %>%
filter(receiver.location== "DEU, Templin") %>%
filter(date == max(date)) %>%
select(contains("receive"))
# select continuous column names
transport_data %>%
filter(receiver.location== "DEU, Templin") %>%
filter(date == max(date)) %>%
select(sender.location:receiver.longitude)
# rearrange the order of the columns. If you have many columns, and you want one column to be the first column, and then use everything().
transport_data %>%
filter(receiver.location== "DEU, Templin") %>%
filter(date == max(date)) %>%
select(number.of.items,everything())