I am looking for a solution to the problem below that would be supported in pipes.
I have data that looks like this:
tibble(
column_set_1_1 = c(1, 2,
Here is a solution that I came up with that works with pipes:
df_foo %>%
gather(key = Key, value = Value, -ID) %>%
mutate(set = str_extract(Key, "column_set_[0-9]")) %>%
mutate(number = str_extract(Key, "(?<=column_set_[0-9]_)[0-9]+")) %>%
group_by(ID, set) %>%
dplyr::filter(!is.na(Value)) %>%
arrange(number) %>%
slice(n()) %>%
select(-number, -Key) %>%
spread(key = set, value = Value)
I don't like the fact that I have to arrange and then slice out the last row -- seems inelegant to me. Any improvements welcome.