Splitting a string into new rows in R
Posted
by
user3703195
on Stack Overflow
See other posts from Stack Overflow
or by user3703195
Published on 2014-08-20T09:42:19Z
Indexed on
2014/08/20
10:20 UTC
Read the original article
Hit count: 228
r
I have a data set like below:
Country Region Molecule Item Code
IND NA PB102 FR206985511
THAI AP PB103 BA-107603 / F000113361 / 107603
LUXE NA PB105 1012701 / SGP-1012701 / F041701000
IND AP PB106 AU206985211 / CA-F206985211
THAI HP PB107 F034702000 / 1010701 / SGP-1010701
BANG NA PB108 F000007970/25781/20009021
I want to split based the string values in ITEMCODE
column on /
and create a new row for each entry.
For instance, the desired output will be:
Country Region Molecule Item Code New row
IND NA PB102 FR206985511 FR206985511
THAI AP PB103 BA-107603 / F000113361 / 107603 F000113361
107603
BA-107603
LUXE NA PB105 1012701 / SP-1012701 / F041701000 1012701
SP-1012701
F041701000
IND AP PB106 AU206985211 / CA-F206985211 AU206985211
CA-F206985211
THAI HP PB107 F034702000 / 1010701 / SP-1010701 F034702000
1010701
SP-1010701
BANG NA PB108 F000007970/25781/20009021 F000007970
25781
20009021
I tried the below code
library(splitstackshape)
df2=concat.split.multiple(df1,"Plant.Item.Code","/", direction="long")
but got the Error
"Error: memory exhausted (limit reached?)"
When i tried strsplit()
i got the below error message.
Error in strsplit(df1$Plant.Item.Code, "/") : non-character argument
Any help from you will be appreciated.
© Stack Overflow or respective owner