将列中以逗号分隔的字符串拆分为单独的行
我有一个数据框,如下所示:
data.frame(director = c("Aaron Blaise,Bob Walker", "Akira Kurosawa", "Alan J. Pakula", "Alan Parker", "Alejandro Amenabar", "Alejandro Gonzalez Inarritu", "Alejandro Gonzalez Inarritu,Benicio Del Toro", "Alejandro González Iñárritu", "Alex Proyas", "Alexander Hall", "Alfonso Cuaron", "Alfred Hitchcock", "Anatole Litvak", "Andrew Adamson,Marilyn Fox", "Andrew Dominik", "Andrew Stanton", "Andrew Stanton,Lee Unkrich", "Angelina Jolie,John Stevenson", "Anne Fontaine", "Anthony Harvey"), AB = c('A', 'B', 'A', 'A', 'B', 'B', 'B', 'A', 'B', 'A', 'B', 'A' , 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'A'))
如您所见,director
列中的某些条目是由逗号分隔的多个名称。我想将这些条目拆分为单独的行,同时保持另一列的值。例如,上面数据框中的第一行应该分成两行,director
列中各有一个名称,列中有“A” AB
。
郎朗坤