game_films <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2026/2026-06-09/game_films.csv')
## Rows: 439 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (14): category, subcategory, title, director, release_date_raw, air_dat...
## dbl (5): worldwide_box_office, rotten_tomatoes, metacritic, budget_low, bu...
## date (1): release_date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ncol_num <- game_films %>%
select(where(is.numeric)) %>%
ncol()
ncol_num
## [1] 5
count_columns <- function(data) {
data %>%
select(where(is.numeric)) %>%
ncol()
}
count_columns(game_films)
## [1] 5
count_columns <- function(data, type) {
if (type == "numeric") {
data %>%
select(where(is.numeric)) %>%
ncol()
} else {
ncol(data)
}
}
count_columns(game_films, "numeric")
## [1] 5
game_num <- game_films %>%
filter(!is.na(title)) %>%
nrow()
game_num
## [1] 439
game_num <- game_films %>%
filter(!is.na(title)) %>%
nrow()
game_num
## [1] 439
count_rows <- function(data) {
data %>%
filter(!is.na(title)) %>%
nrow()
}
count_rows(game_films)
## [1] 439
count_rows <- function(data, game_title) {
data %>%
filter(title == game_title) %>%
nrow()
}
count_rows(game_films, "The Last of Us")
## [1] 0
Create your own.
missing_titles <- game_films %>%
filter(is.na(title)) %>%
nrow()
missing_titles
## [1] 0
Use the filter() function to select rows that meet a condition. Refer to Chapter 5.2 Filter rows with filter()
count_missing_titles <- function(data) {
data %>%
filter(is.na(title)) %>%
nrow()
}
count_missing_titles(game_films)
## [1] 0