I have a problem with split column value when element of column has different number of strings. I can do it in plyr e.g.:
library(plyr)
column <- c("jake", "jane jane","john john john")
df <- data.frame(1:3, name = column)
df$name <- as.character(df$name)
df2 <- ldply(strsplit(df$name, " "), rbind)
View(df2)
As a result, we have data frame with number of column related to maximum number of stings in given element.
When I try to do it in dplyr, I used do
function:
library(dplyr)
df2 <- df %>%
do(data.frame(strsplit(.$name, " ")))
but I get an error:
Error in data.frame("jake", c("jane", "jane"), c("john", "john", "john" : arguments imply differing number of rows: 1, 2, 3
It seems to me that it should be used rbind
function but I do not know where.