我有一个带有向量的数据框,该向量具有由分隔符“;”分隔的多个字符串组合 该向量中的字符串没有任何顺序。我想知道是否有办法通过分隔符将该向量中的字符串分隔为多个唯一向量(虚拟变量),其名称对应于每个唯一字符串。
以下示例来自具有 >100k 行的数据框:
structure(list(Error = structure(1:4, .Label = c("Caller Relationship;Incorrect Department;Incorrect Location", "Facility Information;Incorrect Department", "Incident Date", "Information;IVR"), class = "factor")), .Names = "Error", class = "data.frame", row.names = c(NA, -4L))
我需要的结果是:
structure(list(Error = structure(1:4, .Label = c("Caller Relationship;Incorrect Department;Incorrect Location", "Facility Information;Incorrect Department", "Incident Date", "Information;IVR"), class = "factor"), Caller.Relationship = c(1L, NA, NA, NA), Incorrect.Department = c(1L, 1L, NA, NA), Incorrect.Location = c(1L, NA, NA, NA), Facility.Information = c(NA, 1L, NA, NA), Incident.Date = c(NA, NA, 1L, NA), Information = c(NA, NA, NA, 1L), IVR = c(NA, NA, NA, 1L)), .Names = c("Error", "Caller.Relationship", "Incorrect.Department", "Incorrect.Location", "Facility.Information", "Incident.Date", "Information", "IVR"), class = "data.frame", row.names = c(NA, -4L))