Вы можете использовать функциональность пакета lubridate
для обработки объектов даты и времени. Для ваших данных вам просто нужно добавить 2017
в ваши строки времени данных, а затем преобразовать их в объекты времени данных. После этого вы легко проведете сравнения и фильтрации:
библиотека (lubridate)
# simulation
seasons_g_2017 = data.frame(name = 2017,
starts_on = "April 2",
ends_on = "November 1", stringsAsFactors = FALSE)
players_data = data.frame(name = c("John", "Bill"), birth_date = c("January 15", "June 15"), stringsAsFactors = FALSE)
# OP's data
# create variable that is the month-day of the start of the 2017 season
start_2017 <- ymd(paste0(2017, seasons_g_2017[seasons_g_2017$name == 2017, ]$starts_on, sep = " "))
# create variable that is the month-day of the end of the 2017 season
end_2017 <- ymd(paste0(2017, seasons_g_2017[seasons_g_2017$name == 2017, ]$ends_on, sep = " "))
# create column in players_data that shows month-day of the player's birthday
players_data$birth_date_filter <- ymd(paste0(2017, players_data$birth_date, sep = " "))
# filter players_data to only players who have a birthday during the actual season
players_data <- players_data[players_data$birth_date_filter >= start_2017 &
players_data$birth_date_filter <= end_2017,]
players_data
Выход:
name birth_date birth_date_filter
2 Bill June 15 2017-06-15