library(dplyr)
library(tidyr)

Create a small dataset to test the reshape code.

events <- data_frame(
  event_id = c(1001, 1002, 1003),
  side_a = c("blue", "red", "green"),
  side_b = c("red", "green", "blue"),
  outcome = c("victory", "victory", "peace"),
  winner = c(1, 2, 1)
)

The data we start with has three events:

events
event_id side_a side_b outcome winner
1001 blue red victory 1
1002 red green victory 2
1003 green blue peace 1

We reshape based on who won. The steps are:

  1. Create two new binary variables side_a_won and side_b_won that indicate whether each side won
  2. Gather the newly created variables into a single win_status variable
  3. Create a new side variable to include the name of the actor
  4. Create two separate variables victory and peace from the outcome variable
  5. Optional: Select only the columns we care about
  6. Optional: Use arrange() to make sure the resulting dataframe maintains the same order as the initial
events %>%
  mutate(side_a_won = winner == 1, 
         side_b_won = winner == 2) %>%
  gather(side, win_status, side_a_won, side_b_won)  %>%
  mutate(side = ifelse(side == "side_a_won", side_a, side_b)) %>%
  mutate(victory = outcome == "victory", 
         peace = outcome == "peace") %>%
  select(event_id, side, win_status, victory, peace) %>%
  arrange(event_id)
event_id side win_status victory peace
1001 blue TRUE TRUE FALSE
1001 red FALSE TRUE FALSE
1002 red FALSE TRUE FALSE
1002 green TRUE TRUE FALSE
1003 green TRUE FALSE TRUE
1003 blue FALSE FALSE TRUE

And finally we get two observations for each event but a single actor per observation with their victory and outcome status