I have speaking Turns of different lengths. I want to break the Turns into individual words and assign each word to a new column depending on the word's position in the utterance:
test <- data.frame(
Speaker = c("PS1G3","PS1G2","PS1G3","PS1G2"),
N_words = c(2,3,4,1),
Turn = c("can you","what 's the","are you going up","what"),
c5 = c("VM0 PNP","DTQ VBZ AT0","VBB PNP VVG AVP","DTQ"))
The output I'm looking for is this:
test
Speaker N_words Turn c5 w1 w2 w3 w4
1 PS1G3 2 can you VM0 PNP can you <NA> <NA>
2 PS1G2 3 what 's the DTQ VBZ AT0 what 's the <NA>
3 PS1G3 4 are you going up VBB PNP VVG AVP are you going up
4 PS1G2 1 what DTQ what <NA> <NA> <NA>
I know how to split the Turns into individual words but am stuck there:
lapply(test$Turn, function(x) unlist(strsplit(x, "\\s")))