# Votes cast by two animals ranking a variety of fruits and vegetables.
# This is not real data, I made this up.
x <- tibble::tribble(
~voter_id, ~species, ~food, ~ranking,
1, "Rabbit", "Apple", 1,
1, "Rabbit", "Carrot", 2,
1, "Rabbit", "Banana", 3,
2, "Monkey", "Banana", 1,
2, "Monkey", "Apple", 2,
2, "Monkey", "Carrot", 3
)
# Process preferencial data into a single column.
x |>
long_preferences(
food_preference,
id_cols = voter_id,
item_col = food,
rank_col = ranking
)
# The same, but keep the species data.
x |>
long_preferences(
food_preference,
id_cols = voter_id,
item_col = food,
rank_col = ranking,
unused_fn = list(species = dplyr::first)
)
Run the code above in your browser using DataLab