Daten Filtern

BA Inhaltsanalyse: Inhalte öffentlicher Kommunikation KF E
Wintersemester 2025/2026
Dozent
Raum

Felix Dietrich

02 507

Paket mit Hilfsfunktion installieren

# install.packages("pak")
pak::pak("felixdidi/teaching")

Ausgeglichenen Datensatz erstellen

Als Beispiel nutzen wir hier den fbposts Datensatz aus dem tidycomm Paket. Dieser enhält keine Texte, diese müssen wir für die Erstellung des Datensatzes zur manuellen Goldstandard-Codierung noch mit auswählen.

library(tidyverse)

# Stattdessen natürlich die eigenen Daten nutzen
data <-
  tidycomm::fbposts |>
  mutate(across(starts_with("pop"), ~ if_else(.x == 1, TRUE, FALSE))) |> 
  rowid_to_column(var = "id") |> 
  select(-post_id, -coder_id, -n_pictures)

data
# A tibble: 270 × 5
      id type  pop_elite pop_people pop_othering
   <int> <chr> <lgl>     <lgl>      <lgl>       
 1     1 photo FALSE     FALSE      FALSE       
 2     2 photo FALSE     FALSE      FALSE       
 3     3 photo FALSE     FALSE      FALSE       
 4     4 photo FALSE     FALSE      FALSE       
 5     5 photo FALSE     FALSE      FALSE       
 6     6 photo FALSE     FALSE      FALSE       
 7     7 photo FALSE     FALSE      FALSE       
 8     8 photo FALSE     FALSE      FALSE       
 9     9 photo FALSE     FALSE      FALSE       
10    10 photo FALSE     FALSE      FALSE       
# ℹ 260 more rows
categories <- c("pop_elite", "pop_people", "pop_othering")

filtered_data <-
  data |>
  teaching::filter_balanced_categories(
    categories = categories,
    n_rows = 10,
    seed = 42
  )

filtered_data
# A tibble: 10 × 5
      id type  pop_elite pop_people pop_othering
   <int> <chr> <lgl>     <lgl>      <lgl>       
 1   249 photo FALSE     TRUE       FALSE       
 2    15 video FALSE     TRUE       FALSE       
 3   214 link  TRUE      FALSE      FALSE       
 4   157 link  TRUE      FALSE      FALSE       
 5   247 photo TRUE      FALSE      FALSE       
 6   196 photo TRUE      FALSE      FALSE       
 7   213 link  TRUE      TRUE       FALSE       
 8    75 photo FALSE     FALSE      FALSE       
 9   109 video FALSE     FALSE      FALSE       
10    93 photo FALSE     FALSE      FALSE       

Für manuelle Codierung abspeichern

Anschließend können wir die Daten für die manuelle Codierung in Excel vorbereiten und abspeichern:

cleaned_data <-
  filtered_data |>
  # alle automatisch codierten Spalten leeren
  mutate(across(where(is.logical), ~ str_replace_all(.x, ".+", ""))) |>
  # Spalte für Coder ID hinzufügen
  mutate(coder_id = "", .after = id)

cleaned_data
# A tibble: 10 × 6
      id coder_id type  pop_elite pop_people pop_othering
   <int> <chr>    <chr> <chr>     <chr>      <chr>       
 1   249 ""       photo ""        ""         ""          
 2    15 ""       video ""        ""         ""          
 3   214 ""       link  ""        ""         ""          
 4   157 ""       link  ""        ""         ""          
 5   247 ""       photo ""        ""         ""          
 6   196 ""       photo ""        ""         ""          
 7   213 ""       link  ""        ""         ""          
 8    75 ""       photo ""        ""         ""          
 9   109 ""       video ""        ""         ""          
10    93 ""       photo ""        ""         ""          
library(writexl)

cleaned_data |>
  write_xlsx("goldstandard.xlsx")