# NOT RUN {
library(dplyr)
# Load some pivoted data
(x <- purpose$`NNW WNW`)
# Make a tidy representation
cells <- tidy_table(x)
cells <- cells[!is.na(cells$chr), ]
head(cells)
# Select the cells containing the values
datacells <-
cells %>%
filter(row >= 3, col >= 3)
head(datacells)
# Select the row headers
row_headers <-
cells %>%
filter(col <= 2) %>%
select(row, col, header = chr) %>%
split(.$col) # Separate each column of headers
row_headers
# Select the column headers
col_headers <-
cells %>%
filter(row <= 2) %>%
select(row, col, header = chr) %>%
split(.$row) # Separate each row of headers
col_headers
# From each data cell, search for the nearest one of each of the headers
datacells %>%
NNW(col_headers$`1`) %>%
N(col_headers$`2`) %>%
WNW(row_headers$`1`) %>%
W(row_headers$`2`)
# }
Run the code above in your browser using DataLab