Q:

How to use date as filter

My knowledge of R and scripting in general is almost not existent. So I hope you will be patient with this basic question. 
library(lubridate)
date.depature <- c("2016.06.16", "2016.11.16", "2017.01.05", "2017.01.12", "2017.02.25")
airport.departure <- c("CDG", "QNY", "QXO", "CDG", "QNY")
airport.arrival <- c("SYD", "CDG", "QNY", "SYD", "QXO")
amount <- c("1", "3", "1", "10", "5")
date.depature <- as_date(date.depature)
df <- data.frame(date.depature, airport.departure, airport.arrival, amount)

xtabs(as.integer(amount) ~ airport.arrival + airport.departure, df)

With this code we get the sum of the amount as a matrix with the airports as row/column. Now I need just the results for 

2017
2017.01
until 2017.01

A:

Since you're already using lubridate, I'm going to show you an approach using dplyr (part of the tidyverse alongside lubridate).
The solutions all apply. filter alongside month, year and as_date functions from lubridate to create conditions to filter your data, then use the pipe %>% to pass that long to xtabs
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date

date.depature <- c("2016.06.16", "2016.11.16", "2017.01.05", "2017.01.12", "2017.02.25")
airport.departure <- c("CDG", "QNY", "QXO", "CDG", "QNY")
airport.arrival <- c("SYD", "CDG", "QNY", "SYD", "QXO")
amount <- c("1", "3", "1", "10", "5")
date.depature <- as_date(date.depature)
df <- data.frame(date.depature, airport.departure, airport.arrival, amount)

# For 2017
df %>% 
  filter(year(date.depature) == 2017) %>% 
  xtabs(as.integer(amount) ~ airport.arrival + airport.departure, .)
#>                airport.departure
#> airport.arrival CDG QNY QXO
#>             CDG   0   0   0
#>             QNY   0   0   1
#>             QXO   0   4   0
#>             SYD   2   0   0

# 2017.01
df %>% 
  filter(year(date.depature) == 2017, month(date.depature) == 1) %>% 
  xtabs(as.integer(amount) ~ airport.arrival + airport.departure, .)
#>                airport.departure
#> airport.arrival CDG QNY QXO
#>             CDG   0   0   0
#>             QNY   0   0   1
#>             QXO   0   0   0
#>             SYD   2   0   0

# until 2017.01
df %>% 
  filter(date.depature <= as_date("2017.01.01")) %>% 
  xtabs(as.integer(amount) ~ airport.arrival + airport.departure, .)
#>                airport.departure
#> airport.arrival CDG QNY QXO
#>             CDG   0   3   0
#>             QNY   0   0   0
#>             QXO   0   0   0
#>             SYD   1   0   0

Created on 2018-11-19 by the reprex package (v0.2.1)

