Import your data

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.

Create Data frame functions

Example 1: count columns

code snippets

ncol_num <- game_films %>%

    select(where(is.numeric)) %>%

    ncol()

ncol_num
## [1] 5

Turn them into a function

count_columns <- function(data) {

  data %>%
    select(where(is.numeric)) %>%
    ncol()
}

count_columns(game_films)
## [1] 5

Adding arguments for details of operation

count_columns <- function(data, type) {

  if (type == "numeric") {
    data %>%
      select(where(is.numeric)) %>%
      ncol()
  } else {
    ncol(data)
  }
}

count_columns(game_films, "numeric")
## [1] 5

Example 2: count rows

game_num <- game_films %>%

    filter(!is.na(title)) %>%

    nrow()

game_num
## [1] 439

code snippets

game_num <- game_films %>%

    filter(!is.na(title)) %>%

    nrow()

game_num
## [1] 439

Turn them into a function

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

Example 3: count rows

Create your own.

missing_titles <- game_films %>%

    filter(is.na(title)) %>%

    nrow()

missing_titles
## [1] 0

code snippets

Use the filter() function to select rows that meet a condition. Refer to Chapter 5.2 Filter rows with filter()

Turn them into a function

count_missing_titles <- function(data) {

  data %>%
    filter(is.na(title)) %>%
    nrow()
}

count_missing_titles(game_films)
## [1] 0