I would like to create a tibble which looks like this:
# A tibble: 3 x 4
team arsenal chelsea spurs
<chr> <chr> <chr> <chr>
1 arsenal self london north-london
2 chelsea london self london
3 spurs north-london london self
As you can see, the information in the tibble is duplicated. Reading along the first row (team = arsenal), we can see there is a 'north-london' derby between 'arsenal' and 'spurs'. Similarly, reading along the third row (team = spurs), there is a 'north-london' derby between 'spurs' and 'arsenal'.
Let's call this tibble df_derbies
. I created it with the following code:
library(tidyverse)
## create vectors
team <- c("arsenal", "chelsea", "spurs")
arsenal <- c("self", "london", "north-london")
chelsea <- c("london", "self", "london")
spurs <- c("north-london", "london", "self")
## combine vectors into dataframe
df_derbies <- tibble(team, arsenal, chelsea, spurs)
df_derbies
My question is twofold:
1) Is there a way to create the initial vectors so that I do not have to type out duplicate information? This will mean I only have to type 'north-london' once, for example.
2) After the first step, is there a function(s) that can create a tibble as above? This will essentially duplicate the information for the relevant combination of row and column.
The reason for doing so is that I would like to create a larger tibble, with up to 20 rows. I am open to suggestions for a better way to create and combine the vectors!