Skip to content

Instantly share code, notes, and snippets.

@tklebel
Last active July 27, 2021 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tklebel/1c273984958704751c2ef4d2eab32fb6 to your computer and use it in GitHub Desktop.
Save tklebel/1c273984958704751c2ef4d2eab32fb6 to your computer and use it in GitHub Desktop.
library(tidyverse)
df <- read_csv("~\\NPL_DOI_FOS.csv")
df_restructured <- df %>%
select(doi, matches("fos_\\d_name$")) %>%
group_by(doi) %>%
mutate(id = seq_along(doi)) %>%
pivot_longer(starts_with("fos")) %>%
filter(!is.na(value)) %>%
mutate(level = str_extract(name, "\\d") %>% as.numeric()) %>%
group_by(doi, id) %>%
arrange(desc(level)) %>%
slice(1) %>%
select(doi, id, top_fos = value) %>%
ungroup()
df_restructured %>%
write_csv("npl_cleaned.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment