如何拆分包含命名字符的列表

时间:2016-03-11 13:39:38

标签: r

我有一个列表如下。 我想将列表的元素拆分成数据帧,以便捕获第一个,第二个和最后一个""在列表中。我花了几个小时谷歌搜索但不知道从哪里开始。我尝试split函数作为罗马< -split(罗马,f =罗马$ V1),但我得到一个错误,无论如何我不知道如何选择向量的前两个和最后一个元素

我认为列表的结构使事情变得复杂。例如,其中一列是

> head(dput(roman[,1:6]))
list(structure(c("Gagner", "M", "M", "Department of Surgery, Herbert Wertheim School of Medicine, Florida International University, Miami, FL, USA. gagner.michel@gmail.com.", 
"Department of Surgery, Hôpital du Sacre Coeur, Montreal, Canada. gagner.michel@gmail.com."
), .Names = c("LastName", "ForeName", "Initials", "AffiliationInfo", 
"AffiliationInfo")), structure(c("Braghetto", "I", "I", "Department of Surgery, University Hospital \"Dr. Jose J. Aguirre\". Faculty of Medicine, University of Chile, Santiago, Chile."
), .Names = c("LastName", "ForeName", "Initials", "AffiliationInfo"
)), structure(c("Iwaya", "Yugo", "Y", "Department of Gastroenterology, Nagano Municipal Hospital, Nagano, Japan.", 
"Department of Medicine, Division of Gastroenterology, Shinshu University School of Medicine, Matsumoto, Japan."
), .Names = c("LastName", "ForeName", "Initials", "AffiliationInfo", 
"AffiliationInfo")))
[[1]]
                                                                                                                                LastName 
                                                                                                                                "Gagner" 
                                                                                                                                ForeName 
                                                                                                                                     "M" 
                                                                                                                                Initials 
                                                                                                                                     "M" 
                                                                                                                         AffiliationInfo 
"Department of Surgery, Herbert Wertheim School of Medicine, Florida International University, Miami, FL, USA. gagner.michel@gmail.com." 
                                                                                                                         AffiliationInfo 
                                             "Department of Surgery, Hôpital du Sacre Coeur, Montreal, Canada. gagner.michel@gmail.com." 

[[2]]
                                                                                                                        LastName 
                                                                                                                     "Braghetto" 
                                                                                                                        ForeName 
                                                                                                                             "I" 
                                                                                                                        Initials 
                                                                                                                             "I" 
                                                                                                                 AffiliationInfo 
"Department of Surgery, University Hospital \"Dr. Jose J. Aguirre\". Faculty of Medicine, University of Chile, Santiago, Chile." 

[[3]]
                                                                                                        LastName                                                                                                    "Iwaya"                                                                                                         ForeName                                                                                                     "Yugo" 
                                                                                                        Initials 
                                                                                                             "Y" 
                                                                                                 AffiliationInfo 
                                     "Department of Gastroenterology, Nagano Municipal Hospital, Nagano, Japan." 
                                                                                                 AffiliationInfo 
"Department of Medicine, Division of Gastroenterology, Shinshu University School of Medicine, Matsumoto, Japan."

预期输出应为

LastName     FirstName     Affiliation
Gagner            M         Department of Surgery, Hôpital du Sacre Coeur, Montreal, Canada. gagner.michel@gmail.com.
Braghetto         I         Department of Surgery, University Hospital \"Dr. Jose J. Aguirre\". Faculty of Medicine, University of Chile, Santiago, Chile
Iwaya            Yugo        Department of Medicine, Division of Gastroenterology, Shinshu University School of Medicine, Matsumoto, Japan

1 个答案:

答案 0 :(得分:1)

这种使用sapply的方法可能适合您:

'a