Last active
July 27, 2021 09:57
-
-
Save tklebel/1c273984958704751c2ef4d2eab32fb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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