Here is the original table, recreated by using Addins > DATAPASTA > Paste as tribble (requires installation of datapasta package):
Output of pasting as tribble, saved as 'original' (click to open)
original <-
tibble::tribble(
~Data.Turno.Team,
"01-03-2024 1 d",
"01-03-2024 2 a",
"01-03-2024 3 b",
"02-03-2024 1 c",
"02-03-2024 2 a",
"02-03-2024 3 b",
"03-03-2024 1 c",
"03-03-2024 2 a",
"03-03-2024 3 b",
"04-03-2024 1 c",
"04-03-2024 2 d",
"04-03-2024 3 b",
"05-03-2024 1 c",
"05-03-2024 2 d",
"05-03-2024 3 a",
"06-03-2024 1 c",
"06-03-2024 2 d",
"06-03-2024 3 a",
"07-03-2024 1 b",
"07-03-2024 2 d",
"07-03-2024 3 a",
"08-03-2024 1 b",
"08-03-2024 2 d",
"08-03-2024 3 a",
"09-03-2024 1 b",
"09-03-2024 2 c",
"09-03-2024 3 a",
"10-03-2024 1 b",
"10-03-2024 2 c",
"10-03-2024 3 d",
"11-03-2024 1 b",
"11-03-2024 2 c",
"11-03-2024 3 d",
"12-03-2024 1 a",
"12-03-2024 2 c",
"12-03-2024 3 d",
"13-03-2024 1 a",
"13-03-2024 2 c",
"13-03-2024 3 d",
"14-03-2024 1 a",
"14-03-2024 2 b",
"14-03-2024 3 d",
"15-03-2024 1 a",
"15-03-2024 2 b",
"15-03-2024 3 c",
"16-03-2024 1 a",
"16-03-2024 2 b",
"16-03-2024 3 c",
"17-03-2024 1 d",
"17-03-2024 2 b",
"17-03-2024 3 c",
"18-03-2024 1 d",
"18-03-2024 2 b",
"18-03-2024 3 c",
"19-03-2024 1 d",
"19-03-2024 2 a",
"19-03-2024 3 c",
"20-03-2024 1 d",
"20-03-2024 2 a",
"20-03-2024 3 b",
"21-03-2024 1 d",
"21-03-2024 2 a",
"21-03-2024 3 b",
"22-03-2024 1 c",
"22-03-2024 2 a",
"22-03-2024 3 b",
"23-03-2024 1 c",
"23-03-2024 2 a",
"23-03-2024 3 b",
"24-03-2024 1 c",
"24-03-2024 2 d",
"24-03-2024 3 b",
"25-03-2024 1 c",
"25-03-2024 2 d",
"25-03-2024 3 a",
"26-03-2024 1 c",
"26-03-2024 2 d",
"26-03-2024 3 a",
"27-03-2024 1 b",
"27-03-2024 2 d",
"27-03-2024 3 a",
"28-03-2024 1 b",
"28-03-2024 2 d",
"28-03-2024 3 a",
"29-03-2024 1 b",
"29-03-2024 2 c",
"29-03-2024 3 a",
"30-03-2024 1 b",
"30-03-2024 2 c",
"30-03-2024 3 d",
"31-03-2024 1 b",
"31-03-2024 2 c",
"31-03-2024 3 d"
)
Cleaning 'original' to match table in pdf file (click to open)
library(tidyverse)
original
#> # A tibble: 93 × 1
#> Data.Turno.Team
#> <chr>
#> 1 01-03-2024 1 d
#> 2 01-03-2024 2 a
#> 3 01-03-2024 3 b
#> 4 02-03-2024 1 c
#> 5 02-03-2024 2 a
#> 6 02-03-2024 3 b
#> 7 03-03-2024 1 c
#> 8 03-03-2024 2 a
#> 9 03-03-2024 3 b
#> 10 04-03-2024 1 c
#> # ℹ 83 more rows
# Separate single column from datapasta output into three columns and
# intepret date strings as data objects
original |>
separate_wider_delim(
cols = Data.Turno.Team,
names = c('date', 'turno', 'team'),
delim = " "
) |>
mutate(date = parse_date(date, format = '%d-%m-%Y')) -> original
original
#> # A tibble: 93 × 3
#> date turno team
#> <date> <chr> <chr>
#> 1 2024-03-01 1 d
#> 2 2024-03-01 2 a
#> 3 2024-03-01 3 b
#> 4 2024-03-02 1 c
#> 5 2024-03-02 2 a
#> 6 2024-03-02 3 b
#> 7 2024-03-03 1 c
#> 8 2024-03-03 2 a
#> 9 2024-03-03 3 b
#> 10 2024-03-04 1 c
#> # ℹ 83 more rows
Created on 2024-03-27 with reprex v2.0.2
You can now use the table original
to compare directly to the output of any attempts to recreate it.
How to compare table original
to an attempt at recreating it
Suggested solution from above:
Full solution reprex, final table saved as 'reproduction' (click to open)
library(tidyverse)
# Record pattern of day-to-day differences
tribble(
~turno1, ~turno2, ~turno3,
0, 0, 0,
-1, 0, 0,
0, 0, 0,
0, -1, 0,
0, 0, -1
) -> diff_pattern_seed
# Repeat pattern to cover 31 days
map(diff_pattern_seed, \(c) rep(c, 7)) |>
as_tibble() |>
slice(1:31) -> full_diff_pattern
# Apply difference pattern to obtain teams
full_diff_pattern |>
# calculate cumulative effect of day-to-day differences
mutate(across(everything(), cumsum)) |>
# apply differences starting from d a b interpreted as integers mod 4
map2(c(3, 0, 1), \(c, n) (c + n) %% 4) |>
as_tibble() |>
# convert integers mod 4 back to letters
mutate(across(everything(), \(n) letters[n + 1])) -> teams
# Add date column
tibble(date = seq(ymd('2024-03-01'), by = 'days', length.out = 31)) |>
bind_cols(teams)
#> # A tibble: 31 × 4
#> date turno1 turno2 turno3
#> <date> <chr> <chr> <chr>
#> 1 2024-03-01 d a b
#> 2 2024-03-02 c a b
#> 3 2024-03-03 c a b
#> 4 2024-03-04 c d b
#> 5 2024-03-05 c d a
#> 6 2024-03-06 c d a
#> 7 2024-03-07 b d a
#> 8 2024-03-08 b d a
#> 9 2024-03-09 b c a
#> 10 2024-03-10 b c d
#> # ℹ 21 more rows
# Reshape table to conform to original in given pdf
tibble(date = seq(ymd('2024-03-01'), by = 'days', length.out = 31)) |>
bind_cols(teams) |>
pivot_longer(!date, names_to = "turno", values_to = "team") -> reproduction
reproduction
#> # A tibble: 93 × 3
#> date turno team
#> <date> <chr> <chr>
#> 1 2024-03-01 turno1 d
#> 2 2024-03-01 turno2 a
#> 3 2024-03-01 turno3 b
#> 4 2024-03-02 turno1 c
#> 5 2024-03-02 turno2 a
#> 6 2024-03-02 turno3 b
#> 7 2024-03-03 turno1 c
#> 8 2024-03-03 turno2 a
#> 9 2024-03-03 turno3 b
#> 10 2024-03-04 turno1 c
#> # ℹ 83 more rows
Cleaning 'reproduction' to remove string 'turno' from 2nd column (click to open)
reproduction
#> # A tibble: 93 × 3
#> date turno team
#> <date> <chr> <chr>
#> 1 2024-03-01 turno1 d
#> 2 2024-03-01 turno2 a
#> 3 2024-03-01 turno3 b
#> 4 2024-03-02 turno1 c
#> 5 2024-03-02 turno2 a
#> 6 2024-03-02 turno3 b
#> 7 2024-03-03 turno1 c
#> 8 2024-03-03 turno2 a
#> 9 2024-03-03 turno3 b
#> 10 2024-03-04 turno1 c
#> # ℹ 83 more rows
Created on 2024-03-27 with reprex v2.0.2
# Remove string "turno" from column 'turno'
reproduction |>
mutate(turno = turno |> str_remove('turno')) -> reproduction
reproduction
#> # A tibble: 93 × 3
#> date turno team
#> <date> <chr> <chr>
#> 1 2024-03-01 1 d
#> 2 2024-03-01 2 a
#> 3 2024-03-01 3 b
#> 4 2024-03-02 1 c
#> 5 2024-03-02 2 a
#> 6 2024-03-02 3 b
#> 7 2024-03-03 1 c
#> 8 2024-03-03 2 a
#> 9 2024-03-03 3 b
#> 10 2024-03-04 1 c
#> # ℹ 83 more rows
# Compare tables 'original' and 'reproduction'
all(original == reproduction)
#> [1] TRUE
Created on 2024-03-27 with reprex v2.0.2