The Zero's are missing from the string after String Split in R -
Text after "
I have set the data
Dat country datacode Malta 014P100201 Catalonia 014P100202 RAMANNAGAR 014P100203 Kolar 221,500955 MALLUR 221500956 Maddur 221500970 Kopa 221500955 I split a string on the data code using code:
Dat $ splitcode = substr ($ DAT $) Datacode ', 5, 30) but the output is not below as it matched my requirement.
Country SplitCode Malta 014P100201 datacode 100201 Catalonia 014P100202 100202 RAMANNAGAR 014P100203 100,203 Kolar 221500955 955 MALLUR 221500956 956 Maddur 221500970 970 KOPPA 221500955 955 When splitstring '221500955 'I want to be 955 instead of production 955 is done what I need. Can anyone help me here?
Try adding as .character (). But without it, all 0 are coming:
& gt; Dat Country datacode 1 Malta 014P100201 2 Catalonia 014P100202 3 RAMANNAGAR 014P100203 4 Kolar 221,500,955 5 MALLUR 221,500956 6 Maddur 221,500,970 7 Koppa 221,500,955 & gt; & Gt; Str (data) 'data.frame': 7 obs 2 of the variable: $ Country: Factor W / 7 levels "Catalonia", "Kolar", ..: 6 1 to 7 2 5 4 $ 3 $ datacode: Factor w / 6 Level "014P100201", "014P100202", ..: 1 2 3 4 5 6 4 & gt; & Gt; $ $ Splitcode_ori = substr (dat $ 'datacode', 5, 30) & gt; $ $ Splitcode = as.character (substr (dat $ 'datacode', 5, 30)) & gt; & Gt; Day country datecode splitcode_ori splitcode 1 malta 014P100201 100201 100201 2 Catalonia 014 p 100202 100202 100202 3 Ramanager 014 p 100203 100203 100203 4 Kolar 221500955 00955 00 9 55 5 Mallor 221500956 00 9 56 00 9 6 6 221500970 00970 00 9 70 7 KOPPA 221500955 00 9 55 00 9 55 & gt; & Gt; Str (data) 'data.frame': 7 obs 4 variable: $ country: factor w / 7 level "catlonia", "kolar", ..: 6 1 7 2 5 4 $ $ datasource: factor w / 6 level " 014P100201 "," 014P100202 ", ..: 1 2 3 4 5 6 4 $ splitcode_ori: chr" 100201 "" 100202 "" 100203 "" 00955 "... $ partition: chr" 100201 "" 100202 "" 100203 " 00955 "... & gt; To avoid going to write.csv in 0s, write.csv (..., quote = TRUE)
Comments
Post a Comment