I'm working on a solution to clean up some data, but am not 100% sure what the best solution is. I've found a working solution, but would like to know if there was an easier approach (especially in trying to scale it). What I would like to do is separate all the elements in a dataframe (separated by semicolons), apply each of those components to an element of the dataframe, then combine the results into a new dataframe. Example below:
test <- data.frame(class=c("a1", "a2","a3","a4"),
person=c("p1;p3;p4","p2;p4","p4;p5;p6","p1;p5"),
stringsAsFactors = F)
test1 <- c()
test2 <- c()
for (i in 1:nrow(test)){
test1 <-append(test1, strsplit(test[i,2],";")[[1]])
test2 <- append(test2, rep(test[i,1],length(strsplit(test[i,2],";")[[1]])))
}