0

パターンを、置き換えるパターンを含む別のパターンに置き換えようとしていますqdap::mgsub。問題は、常に置換で元のパターンをもう一度置き換えることです。たとえば、次のようになります。

library(qdap)
mgsub(c("102", "981"), c("ow_102", "Q_1028"), c("102", "981", "102", "981", "981", "981"))

与えます:

[1] "ow_102"    "Q_ow_1028" "ow_102"    "Q_ow_1028" "Q_ow_1028" "Q_ow_1028"

私がそれを私に与えたい場所:

[1] "ow_102"  "Q_1028"  "ow_102"  "Q_1028"  "Q_1028"  "Q_1028"

qdap:mgsub関数が2回実行されるのを防ぐ、またはそれ自体の置換の一部を置換するために行うことを防ぐ引数を見つけることができません。

編集:

パケットstringiは他のポイントで失敗するため、拡張例を次に示します。

#Patterns to be replaced:
x <- c(93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 
104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 
115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 
126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 
137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 
148L, 149L, 150L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L, 
527L, 528L, 529L, 530L, 531L, 532L, 533L, 534L, 535L, 536L, 537L, 
538L, 539L, 540L, 934L, 935L, 936L, 937L, 938L, 939L, 940L, 941L, 
942L, 943L, 944L, 945L, 946L, 947L, 948L, 949L, 950L, 951L, 952L, 
953L, 954L, 955L, 956L, 957L, 958L, 959L, 960L, 961L, 962L, 963L, 
964L, 965L, 966L, 967L, 968L, 969L, 970L, 971L, 972L, 973L, 974L, 
975L, 976L, 977L, 978L, 979L, 980L, 981L, 982L, 983L, 984L, 985L, 
986L, 987L, 988L, 989L, 990L, 991L, 992L, 993L, 994L, 995L, 996L, 
997L, 998L, 999L, 1005L, 1008L, 1009L)
    
#Replacement (so the first "pattern to be replaced" is to be replaced by the first "replacement", the second with the second and so on)
rep <- c("ow_93", "ow_94", "ow_95", "ow_96", "ow_97", "ow_98", "ow_99", 
"ow_100", "ow_101", "ow_102", "ow_103", "ow_104", "ow_105", "ow_106", 
"ow_107", "ow_108", "ow_109", "ow_110", "ow_111", "ow_112", "ow_113", 
"ow_114", "ow_115", "ow_116", "ow_117", "ow_118", "ow_119", "ow_120", 
"ow_121", "ow_122", "ow_123", "ow_124", "ow_125", "ow_126", "ow_127", 
"ow_128", "ow_129", "ow_130", "ow_131", "ow_132", "ow_133", "ow_134", 
"ow_135", "ow_136", "ow_137", "ow_138", "ow_139", "ow_140", "ow_141", 
"ow_142", "ow_143", "ow_144", "ow_145", "ow_146", "ow_147", "ow_148", 
"ow_149", "ow_150", "gw_t_198", "gw_f_199", "gw_f_200", "gw_t_201", 
"gw_f_202", "gw_t_203", "gw_t_204", "gw_t_205", "Parmen_OP", 
"Parmen_UP", "Schönerm.-Wilhelmsh._Besch.mst", "HyDdw_7/79_OP,_Bollmannshof", 
"HyDdw_7/79_UP,_Bollmannshof", "HyDdw_8/78,_Schapow", "HyDdw_11/78,_Fischershof", 
"Prenzlau,_Kuhdamm_OP", "Prenzlau,_Kuhdamm_UP", "HyPr_109/84_OP,_SchenkenbergOP", 
"HyPr_109/84_UP,_SchenkenbergUP", "HyPr_110/84_OP,_Kleptow_OP", 
"HyPr_110/84_UP,_Kleptow_UP", "Gerswalde,Beschaffenheitsmst.", 
"Soll_Q28", "Soll_Q40", "Soll_Q52", "Soll_Q87", "Soll_Q88", "Soll_Q91", 
"Soll_Q93", "Soll_Q133", "Soll_Q149", "Soll_Q183", "Soll_Q187", 
"Soll_Q190", "Soll_Q235", "Soll_Q236", "Soll_Q258", "Soll_Q259", 
"Soll_Q265", "Soll_Q269", "Soll_Q274", "Soll_Q275", "Soll_Q287", 
"Soll_Q311", "Soll_Q312", "Soll_Q341", "Soll_Q393", "Soll_Q394", 
"Soll_Q606", "Soll_Q607", "Soll_Q608", "Soll_Q630", "Soll_Q639", 
"Soll_Q805", "Soll_Q807", "Soll_Q808", "Soll_Q878", "Soll_Q879", 
"Soll_Q880", "Soll_Q882", "Soll_Q892", "Soll_Q893", "Soll_Q907", 
"Soll_Q908", "Soll_Q910", "Soll_Q911", "Soll_Q939", "Soll_Q940", 
"Soll_Q942", "Soll_Q1028", "Soll_Q1061", "Soll_Q1189", "Soll_Q1228", 
"Soll_Q1229", "Soll_Q1338", "Soll_Q1362", "Soll_Q1510", "Soll_Q1590", 
"Soll_Q1598", "Soll_Q1599", "Soll_Q1604", "Soll_Pfützentyp_ggü_Q1604", 
"Soll_Q2484", "Soll_Q2489", "Soll_Q2565", "Soll_Q?_S021_Boisterfelde", 
"Soll_Q647", "Soll_Q388", "Soll_Q319", "Soll_Rittgarten", "Soll_Kraatz")
    
#Vector wherein the replacements are to take place
art <- c(112L, 93L, 95L, 97L, 98L, 100L, 118L, 128L, 133L, 110L, 108L, 
107L, 104L, 107L, 104L, 108L, 110L, 100L, 133L, 112L, 93L, 95L, 
97L, 98L, 128L, 133L, 118L, 128L, 112L, 93L, 95L, 97L, 98L, 100L, 
110L, 108L, 107L, 104L, 112L, 93L, 95L, 97L, 98L, 100L, 118L, 
128L, 133L, 110L, 108L, 107L, 104L, 112L, 93L, 95L, 97L, 98L, 
100L, 110L, 108L, 107L, 104L, 128L, 118L, 133L, 948L, 949L, 953L, 
940L, 939L, 937L, 938L, 994L, 983L, 995L, 969L, 970L, 972L, 973L, 
982L, 990L, 996L, 133L, 110L, 108L, 107L, 104L, 112L, 93L, 95L, 
97L, 98L, 100L, 118L, 128L, 133L, 104L, 107L, 108L, 110L, 100L, 
98L, 97L, 95L, 118L, 112L, 93L, 128L, 112L, 93L, 95L, 97L, 98L, 
118L, 128L, 133L, 104L, 108L, 110L, 107L, 100L, 133L, 107L, 104L, 
108L, 110L, 100L, 98L, 97L, 112L, 93L, 95L, 118L, 128L, 112L, 
93L, 95L, 97L, 98L, 100L, 107L, 110L, 108L, 104L, 133L, 118L, 
128L, 133L, 107L, 104L, 108L, 110L, 100L, 98L, 97L, 93L, 95L, 
118L, 128L, 112L, 93L, 95L, 97L, 98L, 118L, 128L, 133L, 104L, 
107L, 108L, 110L, 100L, 112L, 93L, 95L, 97L, 98L, 100L, 110L, 
128L, 133L, 107L, 104L, 108L, 110L, 100L, 98L, 97L, 112L, 93L, 
95L, 118L, 128L, 203L, 202L, 201L, 200L, 198L, 199L, 204L, 955L, 
952L, 967L, 949L, 974L, 966L, 948L, 953L, 976L, 954L, 975L, 956L, 
957L, 977L, 988L, 941L, 945L, 950L, 951L, 958L, 959L, 963L, 964L, 
965L, 969L, 970L, 971L, 972L, 973L, 960L, 961L, 962L, 981L, 983L, 
984L, 987L, 984L, 994L, 995L, 112L, 93L, 95L, 97L, 98L, 100L, 
110L, 108L, 107L, 104L, 133L, 118L, 128L, 936L, 942L, 943L, 944L, 
946L, 947L, 978L, 979L, 980L, 986L, 989L, 990L, 991L, 992L, 996L, 
997L, 935L, 934L, 993L, 112L, 93L, 95L, 97L, 98L, 118L, 128L, 
133L, 100L, 110L, 108L, 107L, 104L, 949L, 966L, 963L, 998L, 964L, 
959L, 999L, 958L, 995L, 983L, 994L, 949L, 953L, 952L, 948L, 954L, 
955L, 956L, 988L, 967L, 966L, 966L, 966L, 966L, 949L, 949L, 949L, 
112L, 93L, 95L, 97L, 98L, 100L, 107L, 104L, 108L, 110L, 133L, 
118L, 128L, 957L, 965L, 968L, 971L, 973L, 972L, 992L, 993L, 996L, 
986L, 990L, 991L, 989L, 936L, 980L, 979L, 978L, 976L, 974L, 977L, 
984L, 985L, 987L, 934L, 949L, 949L, 949L, 966L, 966L, 966L, 947L, 
961L, 960L, 945L, 944L, 943L, 951L, 950L, 949L, 966L, 966L, 967L, 
988L, 112L, 93L, 95L, 97L, 98L, 118L, 128L, 133L, 100L, 107L, 
108L, 104L, 941L, 953L, 952L, 949L, 948L, 949L, 966L, 949L, 949L, 
949L, 966L, 966L, 966L, 997L, 1005L, 934L, 994L, 995L, 983L, 
949L, 949L, 949L, 966L, 966L, 966L, 949L, 966L, 112L, 93L, 95L, 
97L, 98L, 133L, 104L, 100L, 118L, 128L, 949L, 966L, 949L, 949L, 
949L, 966L, 966L, 966L, 949L, 966L, 949L, 949L, 949L, 966L, 966L, 
966L, 112L, 93L, 95L, 98L, 100L, 104L, 118L, 128L, 133L, 97L, 
949L, 966L, 966L, 966L, 966L, 949L, 949L, 949L, 949L, 966L, 949L, 
949L, 949L, 966L, 966L, 966L, 949L, 966L, 949L, 949L, 949L, 966L, 
966L, 966L, 950L, 951L, 954L, 955L, 956L, 948L, 952L, 953L, 133L, 
104L, 100L, 98L, 97L, 95L, 93L, 112L, 128L, 118L, 107L, 949L, 
966L, 949L, 949L, 949L, 966L, 966L, 966L, 949L, 966L, 949L, 949L, 
949L, 966L, 966L, 966L, 941L, 945L, 944L, 943L, 994L, 961L, 957L, 
965L, 963L, 959L, 958L, 983L, 980L, 970L, 971L, 972L, 990L, 974L, 
977L, 133L, 112L, 93L, 95L, 97L, 98L, 100L, 118L, 128L, 107L, 
104L, 949L, 966L, 949L, 949L, 949L, 966L, 966L, 966L, 949L, 966L, 
112L, 93L, 95L, 97L, 98L, 100L, 118L, 128L, 133L, 110L, 108L, 
107L, 104L, 133L, 104L, 107L, 108L, 110L, 100L, 98L, 97L, 93L, 
112L, 95L, 118L, 128L, 949L, 966L, 112L, 97L, 98L, 133L, 104L, 
107L, 108L, 110L, 100L, 95L, 93L, 118L, 128L, 202L, 201L, 200L, 
198L, 199L, 104L, 204L, 949L, 966L, 133L, 104L, 107L, 110L, 108L, 
959L, 965L, 994L, 983L, 995L, 960L, 961L, 112L, 93L, 95L, 97L, 
98L, 100L, 118L, 128L, 942L, 943L, 944L, 950L, 951L, 945L, 948L, 
954L, 980L, 978L, 984L, 985L, 934L, 992L, 990L, 986L, 974L, 977L, 
976L, 972L, 956L, 955L, 954L, 953L, 949L, 966L, 949L, 966L, 112L, 
93L, 128L, 118L, 95L, 97L, 98L, 100L, 133L, 104L, 107L, 949L, 
966L, 949L, 949L, 949L, 966L, 966L, 966L, 949L, 966L, 112L, 93L, 
95L, 104L, 107L, 100L, 133L, 97L, 98L, 118L, 128L, 949L, 966L, 
966L, 966L, 949L, 966L, 966L, 966L, 966L, 112L, 93L, 95L, 97L, 
98L, 100L, 104L, 118L, 128L, 133L, 980L, 943L, 972L, 974L, 977L, 
965L, 992L, 990L, 950L, 966L, 956L, 955L, 949L, 966L, 966L, 133L, 
104L, 98L, 97L, 95L, 112L, 93L, 118L, 128L, 983L, 133L, 128L, 
112L, 93L, 95L, 104L, 100L, 97L, 98L, 118L, 133L, 104L, 100L, 
98L, 97L, 95L, 93L, 112L, 118L, 128L, 133L, 104L, 100L, 98L, 
97L, 112L, 93L, 95L, 118L, 128L, 950L, 992L, 990L, 980L, 977L, 
974L, 972L, 965L, 966L, 955L, 956L, 952L, 949L, 133L, 104L, 107L, 
108L, 110L, 100L, 112L, 93L, 95L, 97L, 98L, 118L, 128L, 133L, 
107L, 104L, 108L, 110L, 100L, 98L, 97L, 112L, 93L, 95L, 118L, 
128L, 133L, 107L, 104L, 108L, 110L, 100L, 97L, 118L, 128L, 112L, 
93L, 95L, 98L, 133L, 128L, 112L, 93L, 95L, 97L, 98L, 110L, 108L, 
100L, 118L, 104L, 107L, 965L, 959L, 995L, 983L, 994L, 960L, 961L, 
962L, 985L, 984L, 947L, 980L, 979L, 978L, 942L, 944L, 943L, 945L, 
950L, 974L, 975L, 977L, 976L, 973L, 972L, 966L, 1005L, 993L, 
992L, 986L, 989L, 935L, 934L, 948L, 949L, 954L, 953L, 956L, 955L, 
133L, 128L, 112L, 93L, 95L, 97L, 98L, 100L, 118L, 107L, 104L, 
1009L, 1009L, 1009L, 1008L, 1008L, 1008L, 112L, 93L, 95L, 97L, 
98L, 110L, 108L, 100L, 118L, 128L, 133L, 104L, 966L, 949L, 980L, 
953L, 956L, 955L, 948L, 965L, 972L, 974L, 977L, 989L, 992L, 994L, 
133L, 104L, 118L, 128L, 100L, 95L, 93L, 112L, 97L, 98L, 958L, 
957L, 950L, 949L, 1008L, 1008L, 1008L, 966L, 1009L, 1009L, 1009L, 
1009L, 948L, 949L, 953L, 952L, 954L, 991L, 1008L, 1008L, 1009L, 
1009L, 1009L, 953L, 956L, 948L, 955L, 966L, 133L, 97L, 98L, 118L, 
128L, 112L, 93L, 95L, 980L, 977L, 972L, 994L, 133L, 128L, 112L, 
93L, 95L, 97L, 98L, 118L, 1008L, 1008L, 1009L, 1009L, 949L, 966L, 
133L, 104L, 107L, 98L, 97L, 95L, 118L, 112L, 93L, 128L, 1008L, 
949L, 966L, 949L, 966L, 1008L, 949L, 966L, 133L, 104L, 107L, 
108L, 110L, 100L, 118L, 128L, 112L, 93L, 95L, 97L, 98L, 949L, 
966L, 1008L, 1008L, 1008L, 1009L, 1009L, 1009L, 1009L)
4

0 に答える 0