Maybe what I want to do it's impossible, so I made this question to know if there is a way or not. After reading this question here in stackoverflow I saw that there is a way to split a column in different columns, but it's not what I wanted, I have an app in shiny where I can have tables with values like:
Phones price
Nokia 1234D - J298 6732 - LM 2 103$
Samsung 3342L - J2YY 4372 - YU 3 130$
Samsung 3042X - IKAA 3221 - GN 4 102$
So the user comes and says I want to divide those values in column Phones as I want, so the idea that came to my mind was to make the user write something like (" ", " - ", " ", " - ") because I mean separate nokia, 1234D, J298, 6732, LM 2 in 5 columns given the mentioned separators.
Here is the example code:
library(stringr)
c=c(" "," - "," "," - ")
mytable <-data.table(Phones=c("Nokia 1234D - J298 6732 - LM 2",
"Samsung 3342L - J2YY 4372 - YU 3",
"Samsung 3042X - IKAA 3221 - GN 4"),price= c("103$", "130$", "102$") )
aux = str_split_fixed(mytable$Phones, c, 5)
mytable<-data.table( aux, mytable$price)
But I get the following result which is not what I want it separates as it wants , duplicates the first row.:
V1 V2 V3 V4 V5 V2
1: Nokia 1234D - J298 6732 - LM 2 103$
2: Samsung 3342L J2YY 4372 YU 3 130$
3: Samsung 3042X - IKAA 3221 - GN 4 102$
4: Nokia 1234D J298 6732 LM 2 103$
If you have a better solution it would be really helpful.