Separate contents of field

▼魔方 西西 提交于 2019-12-01 14:07:18

You're looking for separate_rows.

Input:

df <- data.frame(authors = c("Drijgers RL, Verhey FR, Leentjens AF, Köhler S, Aalten P."))

                                                     authors
1 Drijgers RL, Verhey FR, Leentjens AF, Köhler S, Aalten P.

Function:

library(tidyverse)

df %>% separate_rows(authors, sep = ", ")

Output:

       authors
1  Drijgers RL
2    Verhey FR
3 Leentjens AF
4    Köhler S
5    Aalten P.

You can save them in a list like that:

authors_list <- df %>% separate_rows(authors, sep = ", ") %>% pull(authors)

Output:

[1] "Drijgers RL"  "Verhey FR"    "Leentjens AF" "Köhler S"    "Aalten P."   

If you have authors of multiple articles in your list and you want only unique occurences, just add unique() at the end:

authors_list <- df %>% separate_rows(authors, sep = ", ") %>% pull(authors) %>% unique()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!