需要帮助将匹配因子转换为向量以创建虚拟变量

Need Help turning matching factors to a vector to create a dummy variable

我正在从事一个分析自然灾害对利率影响的项目。我试图控制使用欧元的国家。我想匹配一个描述使用欧元的国家的向量,并为每个国家创建一个具有虚拟变量的列:1 如果他们使用欧元,0 如果不使用。

Country EURO
ARG       0
FRA       1
GBR       0
CHN       0

我尝试将欧元类别设置为布尔变量,但没有成功。我对 R 比较陌生,所以我不确定自己的编码是否正确。

我使用以下代码创建了欧元栏:

exchangerates$euro <- exchangerates$Country

我已经预留了一个向量,列出了使用欧元的国家:

euro_countries <- c("AUT", "BEL", "CYP", "EST", "FIN",
                    "FRA", "DEU", "GRC", "IRL", "ITA",
                    "EU28", "LVA", "LTU", "LUX", "MLT",
                    "NLD", "PRT", "SVK", "SVN")

感谢所有帮助。我只想使用因子级别创建一个虚拟类别。

Here is a picture of my data in a table. The euro column just has the countries listed when I want the euro_countries vector to be matched with the countries and a 1 placed where the matched countries are

这是我使用 dput 函数时的输出:

6.625, 6.625, 6.625, 6.625, 6.646758, 8.57, 8.57, 8.57, 41.094167, 
75.804733, 91.579292, 122.432417, 134.506333, 142.171667, 
157.066667, 179.729167, 207.689167, 257.229167, 285.684695, 
308.186667, 328.870833, 359.817527, 398.662222, 437.935, 
477.786741, 516.61739, 526.235513, 573.287957, 525.829201, 
505.66424, 502.901462, 499.766833, 534.56577, 544.739367, 
567.51309, 0.610215, 0.711918, 0.711918, 0.899819, 0.793523, 
0.773006, 0.79674, 0.884758, 1.063449, 0.884104, 0.800652, 
0.728078, 27.144917, 31.698417, 32.281167, 38.598417, 32.738518, 
28.209, 23.957417, 22.595583, 20.293667, 17.071667, 19.063, 
19.09825, 19.5775, 19.570583, 23.376333, 21.729917, 0.826111, 
0.84851, 0.798459, 0.84533, 0.829721, 0.732749, 0.769379, 
0.886609, 0.899704, 0.938627, 1.11751, 1.062552, 0.886034, 
0.805365, 0.80412, 0.797141, 0.730638, 0.682675, 0.719843, 
0.755045, 0.719355, 0.778294, 0.753159, 0.753731, 0.904035, 
0.887397, 0.847186, 6.045025, 5.635942, 7.123367, 9.144992, 
10.596392, 6.188558, 6.036133, 6.97624, 7.894714, 5.99691, 
5.443701, 5.624075, 5.616312, 0.238301, 0.234094, 0.248228, 
0.360607, 0.417515, 0.386279, 0.35015, 0.460783, 0.403429, 
0.430937, 0.554865, 0.660267, 0.862031, 0.966193, 1.021986, 
0.74212, 0.711464, 0.612635, 0.624521, 0.805104, 0.749396, 
0.761251, 0.879964, 0.897884, 0.938627, 1.085401, 1.11751, 
1.062552, 0.886034, 0.805365, 0.80412, 0.797141, 0.730638, 
0.719843, 0.755045, 0.719355, 0.778294, 0.753159, 0.753731, 
0.901659, 0.904035, 0.887397, 0.847186, 0.804251, 0.79669, 
0.778294, 0.847186, 0.643067, 0.80412, 0.639863, 0.75265, 
0.75265, 0.79185, 0.846731, 0.732194, 0.747789, 0.688018, 
0.648582, 0.644185, 0.828501, 1.00191, 1.161858, 1.332267, 
1.369789, 1.055876, 0.916327, 0.90813, 0.972646, 0.830127, 
0.860135, 0.807037, 0.863354, 0.846404, 0.760947, 0.779856, 
0.889798, 0.899375, 0.938627, 1.085401, 1.11751, 1.062552, 
0.886034, 0.805365, 0.80412, 0.797141, 0.730638, 0.682675, 
0.719843, 0.755045, 0.719355, 0.778294, 0.753159, 0.753731, 
0.901659, 0.904035, 0.887397, 0.847186, 0.357143, 0.357143, 
0.416667, 0.40039, 0.55651, 0.573272, 0.497641, 0.659725, 
0.751807, 0.779246, 0.682197, 0.611927, 0.611173, 0.563177, 
0.567015, 0.666757, 0.653427, 0.633668, 0.640958, 0.610836, 
0.603824, 0.618057, 0.660931, 0.694655, 0.667223, 0.612472, 
0.54618, 0.549998, 0.499772, 0.543966, 0.641919, 0.647179, 
0.633047, 0.639661, 0.60773, 0.654545, 0.777003, 0.749582, 
0.0773, 0.088042, 0.088042, 0.088041, 0.088041, 0.088041, 
0.088041, 0.088041, 0.10811, 0.107837, 0.108697, 0.125067, 
0.162607, 0.258442, 0.33079, 0.405338, 0.410803, 0.397445, 
0.416318, 0.465191, 0.534898, 0.67278, 0.711967, 0.679861, 
0.706417, 0.801344, 0.86729, 0.896982, 1.072336, 1.11751, 
1.062552, 0.886034, 0.805365, 0.797141, 0.730638, 0.682675, 
0.719843, 0.755045, 0.778294, 0.753731, 0.901659, 0.904035, 
0.887397, 0.847186, 5.434161, 6.160583, 8.277666, 8.341541, 
6.704969, 5.949237, 5.837793, 5.364536, 5.498011, 5.850292, 
5.748165, 6.858304, 6.623831, 6.279025, 60, 48.042208, 45.83215, 
78.988392, 152.646667, 186.789167, 237.145833, 282.179167, 
286.49, 257.886667, 224.306667, 202.745833, 199.5825, 210.39, 
183.625833, 172.113333, 207.944167, 225.104167, 223.695, 
232.601667, 281.523333, 274.433333, 149.583333, 296.291667, 
326, 362.833333, 415, 415, 415, 415, 415, 442.045417, 623.0555, 
626.994, 631.756667, 661.42075, 909.264833, 1025.944833, 
1110.58, 1282.56, 1643.848333, 1685.704167, 1770.059167, 
1842.813333, 1950.3175, 2029.920833, 2087.103867, 2160.753675, 
2248.607975, 2342.296292, 2909.38, 10013.6225, 7855.15, 8421.775, 
10260.85, 9311.191667, 8577.133333, 8938.85, 9704.741667, 
9159.316667, 9141, 9698.9625, 10389.9375, 9090.433333, 8770.433333, 
9386.629167, 10461.24, 11865.2113, 13389.41294, 13308.3268, 
13380.83388, 14236.93877, 4.7619, 4.7619, 4.7619, 4.7619, 
4.7619, 4.7619, 4.7619, 4.7619, 4.7619, 4.7619, 4.7619, 4.7619, 
4.7619, 4.7619, 4.7619, 6.359125, 7.5, 7.5, 7.5, 7.5, 7.491935, 
7.594468, 7.742039, 8.101603, 8.375892, 8.960413, 8.738576, 
8.19284, 8.125791, 7.862945, 8.658523, 9.455132, 10.098898, 
11.362583, 12.36875, 12.610833, 12.9615, 13.917083, 16.2255, 
17.5035, 22.742433, 25.918083, 30.493292, 31.373742, 32.427077, 
35.433173, 36.313286, 41.259365, 43.055428, 44.941605, 47.186414, 
48.610319, 46.583284, 45.316467, 44.099975, 45.307008, 41.348533, 
43.505183, 48.405267, 45.725812, 46.670467, 53.437233, 58.597845, 
61.029514, 64.151944, 67.195313, 65.121569, 68.39784, 1.02173, 
0.943578, 0.854428, 0.767669, 0.788885, 0.859929, 0.793622, 
0.8917, 0.938627, 1.085401, 1.062552, 0.886034, 0.805365, 
0.80412, 0.719843, 0.719355, 0.753731, 0.901659, 0.887397, 
0.847186, 0.901342, 0.999517, 1.821717, 24.842767, 31.693742, 
43.013983, 64.691667, 66.5, 78.615947, 122.241811, 0.00035, 
0.056214, 2.279108, 2.459083, 3.011292, 3.44935, 3.800075, 
4
9.342342, 9.655958, 10.789019, 11.285967, 10.897892, 10.899242, 
10.928192, 11.129717, 13.513475, 12.636008, 12.423325, 13.169458, 
12.771992, 13.29245, 15.848267, 18.664058, 18.926517, 19.244342, 
37.881758, 65.903867, 68.037133, 64.349792, 54.322258, 49.409933, 
49.283683, 48.801767, 44.729817, 47.89025, 46.395342, 46.437131, 
55.537075, 55.731725, 54.665458, 1.724365, 1.456408, 1.199768, 
1.456037, 1.507186, 1.111773, 0.826307, 0.797957, 0.842808, 
0.825878, 0.728624, 0.885448, 0.900179, 0.938627, 1.062552, 
0.886034, 0.80412, 0.797141, 0.730638, 0.682675, 0.755045, 
0.778294, 0.753159, 0.904035, 0.847186, 6.259742, 6.214501, 
7.094129, 6.335157, 8.801842, 8.991654, 6.4425, 5.64, 5.604607, 
0.714288, 0.892857, 1.004889, 1.030312, 0.964425, 0.978502, 
1.02668, 1.152795, 1.496773, 1.763992, 2.023372, 1.913161, 
1.694561, 1.526401, 1.672148, 1.733514, 1.861792, 1.686522, 
1.523877, 1.454848, 1.512421, 1.868249, 1.889614, 2.201149, 
2.378751, 2.162191, 1.722099, 1.508681, 1.420273, 1.542056, 
1.360675, 1.387834, 1.265811, 1.234284, 1.219408, 1.433975, 
1.436525, 1.407408, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 1e-06, 2e-06, 3e-06, 1.1e-05, 1.4e-05, 
1.7e-05, 0.000129, 0.002666, 0.187886, 0.7725, 1.245833, 
1.988319, 2.195, 2.253333, 2.453333, 2.664167, 2.93, 3.383333, 
3.49, 3.506833, 3.5165, 3.478467, 3.413175, 3.295842, 3.274033, 
3.128045, 2.924408, 3.011508, 2.825125, 2.7541, 2.637586, 
2.701899, 2.839044, 3.184439, 3.375062, 3.260488, 0.000332, 
0.004422, 0.008482, 0.009155, 0.026508, 0.95, 1.362643, 2.272277, 
3.279292, 3.4754, 3.967108, 4.346075, 4.0939, 4.080033, 3.657642, 
3.235483, 3.103158, 2.76795, 2.409242, 3.120142, 3.0153, 
2.962848, 3.256542, 3.160617, 3.154542, 3.7695, 3.942783, 
3.779333, 3.611717, 0.143404, 0.143404, 0.122281, 0.244029, 
0.306992, 0.552567, 0.849925, 0.746136, 0.785398, 0.720673, 
0.769364, 0.874455, 1.085401, 1.11751, 1.062552, 0.886034, 
0.805365, 0.80412, 0.797141, 0.682675, 0.719843, 0.755045, 
0.753159, 0.753731, 0.901659, 0.904035, 0.887397, 0.847186, 
6e-04, 0.002, 0.002, 0.001718, 0.002128, 0.002243, 0.007639, 
0.076005, 0.165509, 0.203328, 0.308422, 0.716794, 0.887558, 
1.533284, 2.170872, 2.906079, 3.305543, 3.320007, 3.263657, 
2.913653, 2.808983, 2.43825, 2.518858, 3.049325, 3.1779, 
3.4682, 3.327917, 3.349175, 4.005667, 4.059183, 4.052492, 
3.941617, 0.991667, 2.19075, 4.55915, 5.120833, 5.784833, 
9.705083, 24.6199, 28.129167, 29.168525, 31.348483, 30.692025, 
28.813742, 28.284442, 27.190958, 25.580845, 24.852875, 30.367915, 
29.382341, 30.839831, 31.837144, 38.378207, 60.93765, 67.055933, 
58.342801, 62.668133, 4.5, 3.428171, 3.622136, 3.75, 3.75, 
3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 
3.75, 3.75, 1.115852, 1.169535, 1.372995, 1.528088, 1.605086, 
1.504572, 1.220637, 1.070733, 1.029617, 0.985768, 0.819702, 
0.755045, 0.778294, 0.753159, 0.887397, 0.693266, 0.86427, 
0.802792, 0.804146, 0.730638, 0.778294, 0.753731, 4.355892, 
4.481642, 8.603925, 5.91879, 8.262428, 9.737123, 8.086304, 
7.473088, 6.513972, 8.692518, 2.8, 2.8, 2.8, 2.8, 0.233336, 
9e-06, 9e-06, 9e-06, 9e-06, 9e-06, 9e-06, 9e-06, 1.1e-05, 
1.5e-05, 1.4e-05, 1.4e-05, 1.4e-05, 1.6e-05, 1.8e-05, 2.4e-05, 
7.6e-05, 0.000111, 0.000225, 0.000367, 0.000522, 0.000675, 
0.000857, 0.001422, 0.002609, 0.004172, 0.006872, 0.010985, 
0.029609, 0.045845, 0.081405, 0.260724, 0.418783, 0.625219, 
1.225588, 1.507226, 1.500885, 1.425537, 1.343583, 1.428453, 
1.302931, 1.301522, 1.54996, 1.502849, 1.674955, 1.796001, 
1.903768, 2.188542, 2.720009, 3.648133, 0.714286, 0.714286, 
0.714286, 0.714286, 0.714286, 0.679477, 0.869565, 0.869565, 
0.778834, 0.877579, 1.085816, 1.1141, 1.475277, 2.285032, 
2.036033, 2.273468, 2.587321, 2.761315, 3.267742, 3.550798, 
3.627085, 4.299349, 4.607962, 5.528284, 6.109484, 6.939828, 
8.609181, 10.540747, 7.564749, 6.459693, 6.359328, 6.771549, 
7.045365, 8.261223, 8.473674, 7.321222, 7.261132, 8.209969, 
9.655056, 10.852656, 12.758931, 14.709611, 13.333781), diff = c(0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1e-06, 6e-06, 5.3e-05, 
3.4e-05, 0.00012, 0.000661, 0.445255, 0.465965, 0.037088, 
0.00830399999999998, 6.20000000000065e-05, 0.00074200000000002, 
-0.000162999999999913, 0, 0, 0, 0, 2.063757, -0.162628, 0.022672, 
-0.0196429999999999, 0.150655, 0.0413359999999998, 0.0485160000000002, 
0.565942, 0.186188, 0.213845000000001, 0.426793999999999, 
0.922419000000001, 2.615923, 1.15791, 5.524989, 1.804532, 
11.532285, 0, 0, 0, 0, -0.0101870000000001, -0.134584, -0.00744800000000001, 
0.067205, 0.054413, 0.083541, -0.028166, 0.0209820000000001, 
-0.016397, -0.00802900000000006, 0.115648, 0.124152, 0.029504, 
0.292376, 0.064079, -0.148272, -0.0153110000000001, 0.0164599999999999, 
0.00269900000000001, 0.0778920000000001, 0.108912, -0.102809, 
-0.018718, -0.07117, 0.0695170000000001, 0.244448, -0.0418780000000001, 
0.174877, 0.208616, -0.0928800000000001, -0.298649, -0.182162, 
-0.050279, 0.0185, -0.1329, -0.00289500000000009, 0.0900110000000001, 
-0.19203, -0.120696, -0.00366199999999994, 0.070042, 0.07352, 
0.221727, 0.0141239999999998, -0.0404559999999998, 0.0336539999999999, 
0, 0.115259, -0.0927119999999999, 0.038001, -0.031213, 0.217207, 
0.0822959999999999, 0.0657020000000001, 0.148671, 0.0494479999999999, 
-0.135232, 0.022244, 0.046718, -0.015288, -0.097405, 0.036704, 
0.117562, 0.0127050000000001, 0.039005, 0.146774, -0.0549580000000001, 
-0.176518, -0.00124500000000005, -0.00697899999999996, -0.066503, 
-0.047963, 0.037168, 0.0589390000000001, -0.025135, 0.00237600000000004, 
-0.016638, 0, 0, 0, 0, 0, -0.023377, -0.124998, 0.045271, 
0.21223, 0.134881, 0.164905, 0.0395160000000001, -0.1819, 
-0.148391, -0.0495479999999999, 0.0606599999999999, -0.02826, 
-0.0985740000000001, 0.0130079999999999, 0.038807, -0.0549580000000001, 
-0.176518, -0.00124500000000005, -0.00697899999999996, -0.066503, 
-0.047963, 0.037168, 0.035202, -0.03569, 0.0589390000000001, 
-0.025135, 0.000572000000000017, 0.147928, 0.00237600000000004, 
-0.040211, 0, -9.00000000000001e-05, 0.00135, 0.004253, 1.50399, 
0.0784790000000002, 0.076025, 0.286892, 0.0614330000000001, 
-0.107733, -0.000976000000000088, -0.014866, -0.130217, -0.0919329999999998, 
0.0707, 0.115592, 0.00061599999999995, 0.290217, -0.078416, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 1e-06, 2.9e-05, 0.000146, 0.001777, 
0.626407, 0.252983, 0.0874330000000001, 0.072892, 0.082525, 
0.653416, 0.01549, 0.520209, 0.570731, 0.157112, -0.152356, 
-0.490729, -0.259063, -0.228269, -0.113291, 0.165661, -0.240201, 
-0.0863980000000002, 0.28024, 0.20302, 0.196863, 0.973952, 
0.164409, -0.299924, 0.462436, 0, 0.004, -0.01, 0.013, -0.011491, 
0.043284, 0.0557000000000001, -0.000625000000000098, -0.000665999999999833, 
-0.03186, -0.035123, -0.02205, 0.039125, -0.031133, 0.077425, 
0.0307499999999998, -0.00220799999999999, 0.0296910000000001, 
0.0348249999999999, -0.00131599999999987, 0.0626499999999999, 
0.070416, 0.024017, -0.0635079999999999, -0.0952840000000001, 
-0.046716, -0.017217, -0.0210579999999998, 0.063008, 0.0813489999999999, 
0.075564, 0.00680300000000011, -0.00897300000000012, 0.0211490000000001, 
0.098846, 0.00226900000000008, -0.000622000000000122, 0.0636510000000001, 
0.0205569999999999, -0.168266, -0.100033, -0.089256, -0.0773999999999999, 
-0.0602640000000001, -0.00705899999999993, 0.0760609999999999, 
-0.112938, -0.0406319999999999, 0.00965699999999992, 0.0306090000000001, 
0.0763079999999998, 0.172993, 0.0463019999999998, -0.027663, 
-0.00198199999999993, 0, 0, 0, 0, -0.397967, -0.0816409999999999, 
-0.096117, 0.066033, 0.068867, 0.250541, 0.107442, -0.658208, 
-0.307725, -0.027892, -0.246767, 0.071399, -0.109924, 0.215303, 
-0.00150000000000006, 0.0523419999999999, 0.186688, -0.00122800000000001, 
-0.129008, -0.211956, 0.00168100000000004, 0.00866600000000006, 
-0.053477, 0.00505199999999983, -0.0452359999999998, -0.154864, 
0.049642, -0.01078, -0.0107529999999999, -0.00070199999999998, 
-0.00680900000000007, 9e-06, 0.000184, 0.000105, 0.000564, 
0.000685, 0.00085, 0.000694, 0.001808, 0.000931, 0.521184, 
8.481666, 10.12, 5.59, 11.908333, 27.88, 19.689167, 62.3825, 
32.07, 26.476667, 25.605, 21.9425, 37.949166, 44.3125, 13.36, 
41.59, -23.403334, 7.02833300000003, 48.489167, 30.810833, 
95.350833, 53.9983340000001, 2.46083299999998, -81.868333, 
-49.761667, -29.4925000000001, -7.810833, -0.00313099999993938, 
-50.6107280000001, -26.581667, 2.80380299999996, 8.80157500000001, 
75.075338, 83.7758680000001, 22.8336519999999, -28.1239429999999, 
0, 0, 0, 0, 0, 0, 0, -0.0283090000000001, -0.101284, 0.0815919999999999, 
-0.174234, -0.12865, -0.0565530000000001, 0.206156, 0.188, 
0.0831330000000001, 0.344367, 0.616616, 0.516134, 0.269308, 
0, 0.0430079999999999, 1.0181, 0.540184, 0.1912, 0.247366, 
2.856785, -0.267326000000001, -0.0372419999999991, -0.0243580000000012, 
-0.010859, -0.000707999999999487, 0.000253999999999976, -0.00143599999999999, 
-0.000109999999999388, 7.89999999994961e-05, -0.000235999999999237, 
-0.0824840000000009, -0.220879, -0.365906, -0.658877, -0.117239, 
-0.0611470000000001, -0.308808, -0.149128, -0.116575, -0.0523239999999996, 
0.0840550000000002, 0.416989, 0.114277, -0.142798, 0, 0, 
0, 0.201207999999999, 1.475, 1.006392, 1.784275, 1.029475, 
1.122958, 1.488833, 1.933709, 1.771341, 2.427142, 3.764983, 
2.080942, 3.455133, 4.730533, 7.210242, 9.594167, 14.769583, 
21.962942, 41.494425, 51.94975, 48.346083, 56.566333, 83.39425, 
119.691167, 130.785917, 126.236833, 103.782683, -18.228793, 
67.990525, 123.860002, 104.276525, 285.074516, 330.19339, 
331.672994, 211.729314, 204.608175, 373.411127, -249.039555, 
-307.778726, 40.3052299999999, -282.84757, -110.580528, 190.544594, 
-259.686267, -50.4301659999999, -51.2435580000001, 71.8894150000001, 
132.995721, 740.099807, 312.240818, -102.794271, 4.37656800000013, 
0, 0, 0, 0, 0.0117580000000004, 0.640000000000001, 0, 0, 
3.6875, 13.028533, 10.075084, 30.853125, 12.073916, 7.665334, 
14.895, 22.6625, 27.96, 24.631667, 28.455528, 22.501972, 
20.684166, 30.946694, 38.844695, 39.272778, 39.851741, 5.31557199999997, 
9.61812299999997, 47.052444, -47.458756, -20.164961, -2.76277800000003, 
-3.13462899999996, -3.75142999999991, 10.173597, 22.773723, 
0, 0, 0, 0.087574, 0.0108469999999999, -0.067952, 0.023734, 
0.00671200000000005, 0.135768, -0.159271, -0.083452, -0.056026, 
0.60425, 4.5535, 0.582750000000004, 4.029167, -5.29681, -4.529518, 
-1.742333, -1.361834, -2.301916, -3.222, 1.991333, 0.0352500000000013, 
1.881583, -0.00691700000000139, -1.063584, -1.646416, -0.135139, 
0.0223989999999999, -0.050051, 0.046871, -0.015609, -0.0969720000000001, 
0.0366300000000001, 0.11723, 0.013095, 0.038923, 0.0321089999999999, 
-0.0549580000000001, -0.176518, -0.080669, -0.00124500000000005, 
-0.00697899999999996, -0.066503, -0.047963, 0.037168, 0.035202, 
-0.03569, 0.0589390000000001, -0.025135, 0.000572000000000017, 
0.00237600000000004, -0.016638, -0.040211, 0.298875, 0.374984, 
1.487425, 0.81255, 0.239800000000001, -1.121617, -0.360325, 
0.275412999999999, -0.428103000000001, 0.00585300000000011, 
-0.503077, 0.263208000000001, -0.176164, 0, 0, 0.014134, 
0, -0.003193, -0.031236, -0.036129, 0.004243, -0.057354, 
0.027508, 0.123928, 0.105402, 0.201764, 0.104162, 0.0557930000000001, 
-0.099588, 0.011364, -0.0988289999999999, 0.011886, 0.0402530000000001, 
-0.0557080000000001, 0.0118550000000001, 0.118713, 0.01792, 
0.040743, 0.146774, 0.0321089999999999, -0.0549580000000001, 
-0.176518, -0.080669, -0.00124500000000005, -0.00697899999999996, 
-0.066503, 0.037168, 0.035202, -0.03569, 0.0589390000000001, 
-0.025135, 0.000572000000000017, 0.147928, 0.00237600000000004, 
-0.016638, -0.040211, -0.000751999999999975, -0.00756100000000004, 
0.0589390000000001, -0.040211, -0.078664, -0.00124500000000005, 
0.088545, 0, 0, 0.0392, 0.054881, 0.078523, 0.015595, -0.059771, 
-0.039436, -0.00439699999999998, 0.184316, 0.173409, 0.159948, 
0.170409, 0.0375219999999998, -0.313913, -0.139549, -0.00819700000000001, 
0.064516, -0.142519, 0.030008, -0.053098, 0.056317, -0.0169499999999999, 
-0.085457, 0.018909, 0.109942, 0.00957700000000006, 0.039252, 
0.146774, 0.0321089999999999, -0.0549580000000001, -0.176518, 
-0.080669, -0.00124500000000005, -0.00697899999999996, -0.066503, 
-0.047963, 0.037168, 0.035202, -0.03569, 0.0589390000000001, 
-0.025135, 0.000572000000000017, 0.147928, 0.00237600000000004, 
-0.016638, -0.040211, 0, 0, 0.054564, -0.01053, 0.104469, 
0.0167620000000001, 0.067346, 0.087278, 0.092082, 0.027439, 
-0.0970489999999999, -0.0702700000000001, 0.049003, -0.0479959999999999, 
0.00383800000000001, 0.096983, -0.0133300000000001, -0.019759, 
0.00729000000000002, -0.030122, -0.00701200000000002, 0.0142329999999999, 
0.0428740000000001, 0.033724, -0.027432, -0.054751, -0.066292, 
0.00381799999999999, -0.0437150000000001, 0.044194, 0.0979530000000001, 
0.00525999999999993, 0.00890600000000008, 0.00661400000000001, 
-0.031931, 0.0468150000000001, 0.036369, -0.027421, 0.03328, 
0.010742, 0, -1.000000000001e-06, 0, 0, 0, 0, 0.000941999999999998, 
-0.000272999999999995, 0.00086, 0.01637, 0.03754, 0.062395, 
0.072348, 0.074548, 0.005465, -0.013358, 0.018873, -0.011453, 
0.069707, 0.113354, 0.039187, -0.032106, 0.0265559999999999, 
0.094927, 0.0659460000000001, 0.0296919999999999, 0.175354, 
0.045174, -0.0549580000000001, -0.176518, -0.080669, -0.00697899999999996, 
-0.066503, -0.047963, 0.037168, 0.035202, 0.0589390000000001, 
0.000572000000000017, 0.147928, 0.00237600000000004, -0.016638, 
-0.040211, 0.203404999999999, 0.726422, 1.165923, 0.0638749999999995, 
-1.166714, -0.0851040000000003, -0.111444000000001, -0.473256999999999, 
0.214065, 0.506422, 0.043285, 1.110139, -0.182159, -0.344806, 
0, 5.371058, -4.28725, 4.25300900000001, 26.965242, 34.1425, 
22.744166, 45.033334, 4.310833, -28.603333, -33.58, -21.560834, 
-3.16333299999999, 10.8075, -26.764167, -11.5125, 5.60249999999999, 
24.049167, -1.409167, 8.906667, 2.190833, -7.08999999999997, 
0, 146.708334, 29.708333, 36.833333, 23.125, 0, 0, 0, 0, 
27.045417, 181.010083, 3.93849999999998, 4.76266699999996, 
29.664083, 247.844083, 116.68, 84.6351669999999, 171.98, 
361.288333, 41.8558340000002, 84.3549999999998, 72.7541660000002, 
107.504167, 79.6033329999998, 57.1830339999999, 73.6498080000001, 
87.8543, 93.6883170000001, 567.083708, 7104.2425, -2158.4725, 
566.625, 1839.075, -949.658333000001, -734.058333999999, 
361.716667000001, 765.891667, -545.425000000001, -18.3166669999991, 
557.9625, 690.975, -1299.504167, -320, 616.195833999998, 
1074.610833, 1403.9713, 1524.20164, -81.0861399999994, 72.5070799999994, 
856.104890000001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 1.597225, 1.140875, 0, 0, 0, -0.00806500000000021, 
0.102533, 0.147571, 0.359564000000001, 0.274289, 0.584521000000001, 
-0.221837000000001, -0.545736, -0.0670490000000008, -0.262846, 
0.795578000000001, 0.796609, 0.643765999999999, 1.263685, 
1.006167, 0.242082999999999, 0.350667, 0.955583000000001, 
2.308417, 1.278, 5.238933, 3.17565, 4.575209, 0.88045, 1.053335, 
3.006096, 0.880113000000001, 4.946079, 1.796063, 1.886177, 
2.244809, 1.423905, -2.027035, -1.266817, -1.216492, 1.207033, 
-3.958475, 2.15665, 4.900084, -2.679455, 0.944655000000004, 
6.766766, 5.160612, 2.431669, 3.12243, 3.043369, -2.073744, 
3.27627100000001, 0.127121, -0.257105, -0.0891500000000001, 
-0.128186, 0.0212159999999999, 0.113677, 0.00164400000000009, 
0.054126, 0.0469269999999999, 0.146774, -0.0549580000000001, 
-0.176518, -0.080669, -0.00124500000000005, 0.037168, -0.03569, 
)), row.names = c(NA, -1567L), class = "data.frame")

简单地使用ifelse来有条件地赋值%in%:

euro_countries <- c("AUT", "BEL", "CYP", "EST", "FIN",
                    "FRA", "DEU", "GRC", "IRL", "ITA",
                    "EU28", "LVA", "LTU", "LUX", "MLT",
                    "NLD", "PRT", "SVK", "SVN")

exchangerates$euro <- ifelse(exchangerates$country %in% euro_countries, 1, 0)

或者没有ifelse

exchangerates$euro <- as.integer(exchangerates$country %in% euro_countries)