使用 dplyr 添加派生条件列

发布于 2025-01-12 18:44:19 字数 15636 浏览 0 评论 0原文

我正在使用的初始数据集是两家商店的塔纳图拉加班价格列表,一家位于加拿大,另一家位于波兰。

为了在两家商店之间进行公平比较,我想根据每个数据点时的汇率将波兰兹罗提转换为美元。到目前为止,我已经将汇率时间表与狼蛛价格加班合并起来(请参阅下面的代码和示例数据)。但是,我不确定如何创建新的派生列,例如“可比价格”,其中美元价格保持不变,但 PLN 价格转换为美元。我尝试使用 mutate 函数创建一个新列,其中价格列除以转化率,但我正在努力如何仅针对兹罗提中的行设置此条件。

这是要查找的输出 id 类型的示例:

日期1 USD 到 PLN价格货币转换
2013-06-073.24165810$10
2013-06-073.24165820zl6.17
library(priceR)
library(dplyr)

Tarantula <- structure(list(Date = structure(c(15863, 16355, 15930, 15962, 
15903, 16121, 16545, 16575, 16608, 16000, 16639, 16670, 16306, 
16249, 17956, 17988, 18019, 18050, 18111, 18143, 17819, 17646, 
17676, 17707, 17738, 17648, 17770, 17801, 17679, 17710, 17740, 
17833, 17864, 17926, 17895, 18188, 17646, 17676, 17707, 17738, 
17648, 17770, 17679, 17710, 17740, 17833, 17864, 17895, 17444, 
17478, 17387, 17419, 17512, 17542, 17391, 17455, 17489, 17492, 
17584, 17554, 17523, 17433, 17435, 17465, 17526, 17405, 17559, 
17467, 17438, 17500, 15962, 15962, 18111, 18081, 18143, 18918, 
18188, 18578, 18689, 18708, 18923, 18897, 18578, 18689, 18708, 
17444, 17478, 17387, 17418, 17512, 17542, 17433, 17391, 17455, 
18918, 17489, 17584, 17492, 17554, 18923, 17523, 17646, 17435, 
17465, 17526, 17648, 17405, 18897, 17559, 17467, 17438, 17500, 
18578, 18689, 18708, 18923, 18897, 16355, 16545, 16575, 16306, 
16249, 18081, 16846, 16702, 17956, 18111, 18111, 18081, 18143, 
18143, 17819, 18188, 18188, 17738, 17770, 17801, 17740, 17833, 
17864, 17926, 17895, 17801, 17167, 17444, 17478, 17387, 17419, 
17391, 17180, 17300, 17331, 17362, 17455, 17121, 17122, 17489, 
17492, 17433, 17435, 17465, 17405, 17467, 17438, 17500, 16996, 
17028, 17059, 17090, 16969, 17646, 17676, 17707, 17738, 17648, 
17770, 17679, 17710, 17740, 17646, 17988, 18019, 18050, 16608, 
16639, 16867, 17331, 16846, 17362, 16876, 16908, 16939, 17167, 
17180, 17121, 17122, 17444, 17478, 17387, 17418, 17512, 17542, 
17433, 17391, 17455, 18918, 17489, 17492, 17554, 18923, 17523, 
17435, 17465, 17526, 17405, 18897, 17559, 17467, 17438, 17500, 
16545, 16575, 16608, 16639, 16670, 16121, 17478, 17512, 17542, 
18111, 18143, 17300, 17489, 17492, 17554, 17523, 17676, 17707, 
17526, 17559, 17679, 17500, 17710, 16355, 18111, 18081, 18143, 
18188, 18578, 18689, 18918, 18708, 18923, 18897, 18918, 18923, 
18897, 17387, 18578, 17391, 17405, 18923, 18897, 18578, 18689, 
18708, 16867, 16876, 16908, 16969, 16939, 18578, 18689, 18918, 
18708, 18923, 18897, 17988, 17988, 18019, 18050, 18111, 18081, 
18143, 18578, 18689, 17819, 18188, 18708, 17770, 17801, 17833, 
17864, 17926, 17895, 15863, 17956, 17988, 18019, 18050, 18111, 
18081, 18143, 15930, 17819, 15903, 18188, 17646, 17676, 17738, 
17648, 17770, 17801, 17710, 17740, 17833, 17864, 17926, 17895, 
17444, 17478, 17512, 17542, 18578, 18689, 17455, 18918, 17489, 
17584, 18708, 17492, 17554, 18923, 17523, 17435, 17465, 17526, 
18897, 17559, 17467, 17438, 17500, 17801, 17444, 17478, 17512, 
17542, 18578, 18689, 17433, 17819, 17455, 18918, 18188, 17489, 
17584, 18708, 17492, 17554, 18923, 17523, 17646, 17676, 17707, 
17738, 17435, 17465, 17526, 17648, 17770, 17801, 18897, 17559, 
17679, 17710, 17740, 17467, 17438, 17833, 17864, 17926, 17500, 
17895, 17956, 17988, 18019, 18050, 18111, 18081, 18143, 18578, 
18689, 17819, 18918, 18188, 18708, 18923, 17770, 17801, 18897, 
17833, 17864, 17926, 17895, 17444, 17478, 17512, 17542, 17956, 
17988, 18019, 18050, 18081, 18578, 18689, 17433, 17819, 17455, 
17489, 17584, 18708, 17492, 17554, 17523, 17646, 17676, 17707, 
17738, 17435, 17465, 17526, 17648, 17770, 17801, 17559, 17679, 
17710, 17740, 17467, 17438, 17833, 17864, 17926, 17500, 17895, 
16355, 18689, 16545, 16575, 18708, 16608, 16639, 16670, 18923, 
16702, 18897, 17167, 18689, 17090, 17121, 17122, 18918, 16121, 
18708, 18923, 16306, 18897, 16249, 16121, 18923, 18897, 18689, 
18918, 18708, 16867, 16996, 16846, 16876, 16908, 16939, 17980, 
18923, 18578, 18689, 16996, 17090, 16969, 16939, 18918, 18188, 
18708, 18923, 18897, 15962, 16121, 16000, 18578, 18689, 18708, 
17331, 17362, 16306, 17444, 17478, 17387, 17419, 17512, 17542, 
17391, 17300, 17331, 16996, 17362, 17455, 16908, 16969, 16939, 
17489, 17492, 17584, 17554, 17523, 17433, 17646, 17676, 17707, 
17980, 17646, 17738, 17435, 17465, 17526, 17648, 17405, 17770, 
17559, 17679, 17710, 17740, 17467, 17438, 17500, 15930, 15962, 
16121, 16000, 16306, 16249, 15863, 15863, 16355, 15930, 15930, 
15962, 15903, 15903, 16121, 16000, 16306, 16249, 18923, 18897, 
17956, 17988, 18019, 18050, 18111, 18081, 18143, 15962, 17819, 
18188, 16121, 16000, 17770, 17801, 17833, 17864, 17926, 17895, 
18578, 18689, 18918, 18708, 18923, 18897, 18578, 18689, 18918, 
18708, 18923, 18897, 18923, 18897, 16846, 16876, 16306, 17419, 
17391, 17405, 16249, 18019, 18050, 18111, 18081, 18143, 18188, 
18923, 18578, 18689, 18918, 18708, 16996, 16969, 16939, 17167, 
17478, 17090, 17121, 17122, 17489, 17492, 17500, 17444, 17478, 
17512, 17542, 17455, 17489, 17584, 17492, 17554, 17523, 17435, 
17465, 17526, 17559, 17467, 17438, 17500, 17956, 17988, 18019, 
18050, 18081, 17819, 17646, 17676, 17707, 17738, 17648, 17770, 
17801, 17679, 17710, 17740, 17833, 17864, 17926, 17895, 18111, 
18143, 18188, 18578, 18689, 18918, 18708, 18923, 18897, 18578, 
18689, 17819, 18918, 18708, 18923, 17770, 17801, 18897, 17833, 
17864, 17926, 17895, 18578, 18689, 18918, 18708, 18923, 18897, 
17956, 17988, 18019, 18050, 18111, 18081, 18143, 18578, 18689, 
17819, 18188, 18708, 17770, 17801, 17833, 17864, 17926, 17895, 
16939, 17444, 17419, 17391, 17455, 17433, 17435, 17405, 17438, 
18019, 18050, 18111, 18081, 18143, 17387, 17418, 17391, 17405, 
16876, 16908, 18689, 18708, 16306, 16249, 18923, 18918, 18923, 
18897, 15962, 17988, 17819, 17646, 17676, 17707, 17738, 17648, 
17770, 17801, 17679, 17710, 17740, 17833, 17864, 17926, 17895, 
15863, 15930, 15962, 15903, 16121, 16000, 18111, 18143, 17646, 
17676, 17707, 17738, 17648, 17679, 17710, 17740, 18918, 18923, 
18897, 18923, 18897, 18923, 18897, 17551, 17883, 17486, 17456, 
17427, 17610, 17551, 17518, 17486, 17456, 17427, 17610, 17551, 
17610, 17427, 17456, 17427, 19051, 17551, 17518, 17486, 17610, 
17551, 17518, 17486, 17456, 17427, 17486, 17456, 17427, 17551, 
17518, 17486, 17456, 17427, 17551, 17518, 17486, 17427, 17610, 
17610, 17456, 19051), class = "Date"), Price = c(10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 14L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 175L, 175L, 175L, 175L, 
175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 
175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 20L, 20L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 200L, 200L, 200L, 200L, 200L, 
200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 
200L, 200L, 200L, 200L, 200L, 225L, 225L, 225L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 250L, 250L, 250L, 250L, 250L, 250L, 250L, 250L, 250L, 250L, 
250L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 40L, 40L, 40L, 40L, 40L, 
40L, 40L, 40L, 40L, 40L, 40L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 50L, 
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 55L, 55L, 
60L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 
65L, 65L, 65L, 65L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 
75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 85L, 
85L, 100L, 100L, 100L, 100L, 100L, 110L, 110L, 110L, 110L, 120L, 
120L, 125L, 125L, 13L, 150L, 15L, 15L, 200L, 20L, 20L, 20L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 35L, 35L, 40L, 90L), Currency = c("$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", "$", 
"$", "$", "$", "$", "$", "zl", "zl", "zl", "zl", "zl", "zl", 
"zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", 
"zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", 
"zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", 
"zl", "zl", "zl", "zl")), class = "data.frame", row.names = c(NA, 
-817L)) 

#Getting exchange rates from USD to PLN from 2013 to 2019
cur <- historical_exchange_rates("USD", to = "PLN",
                                 start_date = "2013-01-01", end_date = "2022-03-01")

colnames(cur) <- c('Date','1_USD_to_PLN') #changing column names. 

#making sure the date columns are formatted as dates 
cur$Date <- as.Date(cur$Date, format = "%Y.%m.%d") 
Tarantula$Date <- as.Date(Tarantula$Date)
 
#merging the two datasets together for rows where they share a date  
merged <- right_join(cur, Tarantula, by = "Date")   

The initial dataset I am working with is a list of tarnatula prices overtime from two shops, one based in Canada and the other in Poland.

In order to make a fair comparison between the two shops, I want to convert the Polish Zloty to USD, depending on the exchange rate at the time of each data point. So far I've merged a timeline of exchange rates with tarantula prices overtime (See code below with sample data). However, Im unsure how to create a new derived column, e.g. "Comparible prices" where the prices already in USD remain the same but those in PLN are converted to USD. Ive tried to use the mutate function to create a new column where the price column is divided by the conversion rate, but am struggling how to make this conditional for the rows in Zloty only.

This is an example of the kind of output id be looking for:

Date1 USD to PLNPriceCurrencyConverted
2013-06-073.24165810$10
2013-06-073.24165820zl6.17
library(priceR)
library(dplyr)

Tarantula <- structure(list(Date = structure(c(15863, 16355, 15930, 15962, 
15903, 16121, 16545, 16575, 16608, 16000, 16639, 16670, 16306, 
16249, 17956, 17988, 18019, 18050, 18111, 18143, 17819, 17646, 
17676, 17707, 17738, 17648, 17770, 17801, 17679, 17710, 17740, 
17833, 17864, 17926, 17895, 18188, 17646, 17676, 17707, 17738, 
17648, 17770, 17679, 17710, 17740, 17833, 17864, 17895, 17444, 
17478, 17387, 17419, 17512, 17542, 17391, 17455, 17489, 17492, 
17584, 17554, 17523, 17433, 17435, 17465, 17526, 17405, 17559, 
17467, 17438, 17500, 15962, 15962, 18111, 18081, 18143, 18918, 
18188, 18578, 18689, 18708, 18923, 18897, 18578, 18689, 18708, 
17444, 17478, 17387, 17418, 17512, 17542, 17433, 17391, 17455, 
18918, 17489, 17584, 17492, 17554, 18923, 17523, 17646, 17435, 
17465, 17526, 17648, 17405, 18897, 17559, 17467, 17438, 17500, 
18578, 18689, 18708, 18923, 18897, 16355, 16545, 16575, 16306, 
16249, 18081, 16846, 16702, 17956, 18111, 18111, 18081, 18143, 
18143, 17819, 18188, 18188, 17738, 17770, 17801, 17740, 17833, 
17864, 17926, 17895, 17801, 17167, 17444, 17478, 17387, 17419, 
17391, 17180, 17300, 17331, 17362, 17455, 17121, 17122, 17489, 
17492, 17433, 17435, 17465, 17405, 17467, 17438, 17500, 16996, 
17028, 17059, 17090, 16969, 17646, 17676, 17707, 17738, 17648, 
17770, 17679, 17710, 17740, 17646, 17988, 18019, 18050, 16608, 
16639, 16867, 17331, 16846, 17362, 16876, 16908, 16939, 17167, 
17180, 17121, 17122, 17444, 17478, 17387, 17418, 17512, 17542, 
17433, 17391, 17455, 18918, 17489, 17492, 17554, 18923, 17523, 
17435, 17465, 17526, 17405, 18897, 17559, 17467, 17438, 17500, 
16545, 16575, 16608, 16639, 16670, 16121, 17478, 17512, 17542, 
18111, 18143, 17300, 17489, 17492, 17554, 17523, 17676, 17707, 
17526, 17559, 17679, 17500, 17710, 16355, 18111, 18081, 18143, 
18188, 18578, 18689, 18918, 18708, 18923, 18897, 18918, 18923, 
18897, 17387, 18578, 17391, 17405, 18923, 18897, 18578, 18689, 
18708, 16867, 16876, 16908, 16969, 16939, 18578, 18689, 18918, 
18708, 18923, 18897, 17988, 17988, 18019, 18050, 18111, 18081, 
18143, 18578, 18689, 17819, 18188, 18708, 17770, 17801, 17833, 
17864, 17926, 17895, 15863, 17956, 17988, 18019, 18050, 18111, 
18081, 18143, 15930, 17819, 15903, 18188, 17646, 17676, 17738, 
17648, 17770, 17801, 17710, 17740, 17833, 17864, 17926, 17895, 
17444, 17478, 17512, 17542, 18578, 18689, 17455, 18918, 17489, 
17584, 18708, 17492, 17554, 18923, 17523, 17435, 17465, 17526, 
18897, 17559, 17467, 17438, 17500, 17801, 17444, 17478, 17512, 
17542, 18578, 18689, 17433, 17819, 17455, 18918, 18188, 17489, 
17584, 18708, 17492, 17554, 18923, 17523, 17646, 17676, 17707, 
17738, 17435, 17465, 17526, 17648, 17770, 17801, 18897, 17559, 
17679, 17710, 17740, 17467, 17438, 17833, 17864, 17926, 17500, 
17895, 17956, 17988, 18019, 18050, 18111, 18081, 18143, 18578, 
18689, 17819, 18918, 18188, 18708, 18923, 17770, 17801, 18897, 
17833, 17864, 17926, 17895, 17444, 17478, 17512, 17542, 17956, 
17988, 18019, 18050, 18081, 18578, 18689, 17433, 17819, 17455, 
17489, 17584, 18708, 17492, 17554, 17523, 17646, 17676, 17707, 
17738, 17435, 17465, 17526, 17648, 17770, 17801, 17559, 17679, 
17710, 17740, 17467, 17438, 17833, 17864, 17926, 17500, 17895, 
16355, 18689, 16545, 16575, 18708, 16608, 16639, 16670, 18923, 
16702, 18897, 17167, 18689, 17090, 17121, 17122, 18918, 16121, 
18708, 18923, 16306, 18897, 16249, 16121, 18923, 18897, 18689, 
18918, 18708, 16867, 16996, 16846, 16876, 16908, 16939, 17980, 
18923, 18578, 18689, 16996, 17090, 16969, 16939, 18918, 18188, 
18708, 18923, 18897, 15962, 16121, 16000, 18578, 18689, 18708, 
17331, 17362, 16306, 17444, 17478, 17387, 17419, 17512, 17542, 
17391, 17300, 17331, 16996, 17362, 17455, 16908, 16969, 16939, 
17489, 17492, 17584, 17554, 17523, 17433, 17646, 17676, 17707, 
17980, 17646, 17738, 17435, 17465, 17526, 17648, 17405, 17770, 
17559, 17679, 17710, 17740, 17467, 17438, 17500, 15930, 15962, 
16121, 16000, 16306, 16249, 15863, 15863, 16355, 15930, 15930, 
15962, 15903, 15903, 16121, 16000, 16306, 16249, 18923, 18897, 
17956, 17988, 18019, 18050, 18111, 18081, 18143, 15962, 17819, 
18188, 16121, 16000, 17770, 17801, 17833, 17864, 17926, 17895, 
18578, 18689, 18918, 18708, 18923, 18897, 18578, 18689, 18918, 
18708, 18923, 18897, 18923, 18897, 16846, 16876, 16306, 17419, 
17391, 17405, 16249, 18019, 18050, 18111, 18081, 18143, 18188, 
18923, 18578, 18689, 18918, 18708, 16996, 16969, 16939, 17167, 
17478, 17090, 17121, 17122, 17489, 17492, 17500, 17444, 17478, 
17512, 17542, 17455, 17489, 17584, 17492, 17554, 17523, 17435, 
17465, 17526, 17559, 17467, 17438, 17500, 17956, 17988, 18019, 
18050, 18081, 17819, 17646, 17676, 17707, 17738, 17648, 17770, 
17801, 17679, 17710, 17740, 17833, 17864, 17926, 17895, 18111, 
18143, 18188, 18578, 18689, 18918, 18708, 18923, 18897, 18578, 
18689, 17819, 18918, 18708, 18923, 17770, 17801, 18897, 17833, 
17864, 17926, 17895, 18578, 18689, 18918, 18708, 18923, 18897, 
17956, 17988, 18019, 18050, 18111, 18081, 18143, 18578, 18689, 
17819, 18188, 18708, 17770, 17801, 17833, 17864, 17926, 17895, 
16939, 17444, 17419, 17391, 17455, 17433, 17435, 17405, 17438, 
18019, 18050, 18111, 18081, 18143, 17387, 17418, 17391, 17405, 
16876, 16908, 18689, 18708, 16306, 16249, 18923, 18918, 18923, 
18897, 15962, 17988, 17819, 17646, 17676, 17707, 17738, 17648, 
17770, 17801, 17679, 17710, 17740, 17833, 17864, 17926, 17895, 
15863, 15930, 15962, 15903, 16121, 16000, 18111, 18143, 17646, 
17676, 17707, 17738, 17648, 17679, 17710, 17740, 18918, 18923, 
18897, 18923, 18897, 18923, 18897, 17551, 17883, 17486, 17456, 
17427, 17610, 17551, 17518, 17486, 17456, 17427, 17610, 17551, 
17610, 17427, 17456, 17427, 19051, 17551, 17518, 17486, 17610, 
17551, 17518, 17486, 17456, 17427, 17486, 17456, 17427, 17551, 
17518, 17486, 17456, 17427, 17551, 17518, 17486, 17427, 17610, 
17610, 17456, 19051), class = "Date"), Price = c(10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 14L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 175L, 175L, 175L, 175L, 
175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 
175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 175L, 20L, 20L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 200L, 200L, 200L, 200L, 200L, 
200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 
200L, 200L, 200L, 200L, 200L, 225L, 225L, 225L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 250L, 250L, 250L, 250L, 250L, 250L, 250L, 250L, 250L, 250L, 
250L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 40L, 40L, 40L, 40L, 40L, 
40L, 40L, 40L, 40L, 40L, 40L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 50L, 
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 55L, 55L, 
60L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 
65L, 65L, 65L, 65L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 
75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 85L, 
85L, 100L, 100L, 100L, 100L, 100L, 110L, 110L, 110L, 110L, 120L, 
120L, 125L, 125L, 13L, 150L, 15L, 15L, 200L, 20L, 20L, 20L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 35L, 35L, 40L, 90L), Currency = c("
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "
quot;, 
"
quot;, "
quot;, "
quot;, "
quot;, "
quot;, "zl", "zl", "zl", "zl", "zl", "zl", 
"zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", 
"zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", 
"zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", "zl", 
"zl", "zl", "zl", "zl")), class = "data.frame", row.names = c(NA, 
-817L)) 

#Getting exchange rates from USD to PLN from 2013 to 2019
cur <- historical_exchange_rates("USD", to = "PLN",
                                 start_date = "2013-01-01", end_date = "2022-03-01")

colnames(cur) <- c('Date','1_USD_to_PLN') #changing column names. 

#making sure the date columns are formatted as dates 
cur$Date <- as.Date(cur$Date, format = "%Y.%m.%d") 
Tarantula$Date <- as.Date(Tarantula$Date)
 
#merging the two datasets together for rows where they share a date  
merged <- right_join(cur, Tarantula, by = "Date")   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一口甜 2025-01-19 18:44:19

您还可以使用 case_when() 它可以让您在 mutate() 中执行逻辑语句如果您有更多条件,将来可能会有用:

library(dplyr)

converted <- merged %>% 
  mutate(Conversion=as.numeric(`1_USD_to_PLN`),
         Price=as.numeric(Price),
         comparable=case_when(
           Currency=="$" ~ Price,
           Currency=="zl" ~ Price/Conversion
         ))

另请注意,您可以使用一对反引号 (`) 来引用否则保留或非法的名称或符号组合。

You could also use case_when() which lets you do logical statements in a mutate() and might be useful in the future if you have more conditions:

library(dplyr)

converted <- merged %>% 
  mutate(Conversion=as.numeric(`1_USD_to_PLN`),
         Price=as.numeric(Price),
         comparable=case_when(
           Currency=="
quot; ~ Price,
           Currency=="zl" ~ Price/Conversion
         ))

Also as a note, you can use a pair of backticks (`) to refer to names or combinations of symbols that are otherwise reserved or illegal.

清君侧 2025-01-19 18:44:19

我想在与 dplyr 玩了一段时间后我已经成功回答了我自己的问题!

之前我尝试过这个:

converted <- mutate(merged, Converted = ifelse(merged$Currency=="$", (merged$Price), (merged$Price/merged$1_USD_to_PLN)))

并且还尝试了 1_USD_to_PLN 周围的语音标记,但这两个都返回了错误。

现在这似乎有效:

converted <- mutate(merged, Converted = ifelse(merged$Currency=="$", (merged$Price), (merged$Price/merged[,2])))

完整的代码:

Tarantula <- read.csv("Tarantula_Data.csv")

#Getting exchange rates from USD to PLN from 2013 to 2019
cur <- historical_exchange_rates("USD", to = "PLN",
                                 start_date = "2013-01-01", end_date = "2022-03-01")

colnames(cur) <- c('Date','1_USD_to_PLN') #changing column names

#making sure the date columns are formatted as dates
cur$Date <- as.Date(cur$Date, format = "%Y.%m.%d")
Tarantula$Date <- as.Date(Tarantula$Date)

#merging the two datasets together for rows where they share a date
merged <- right_join(cur, Tarantula, by = "Date") 

as.factor(merged$Currency)

converted <- mutate(merged, Converted = ifelse(merged$Currency=="$", (merged$Price), (merged$Price/merged[,2])))

I think I've managed to answer my own question after a bit of playing round with dplyr!

Previously I had tried this:

converted <- mutate(merged, Converted = ifelse(merged$Currency=="
quot;, (merged$Price), (merged$Price/merged$1_USD_to_PLN)))

And also tried it with speech marks around the 1_USD_to_PLN, but both of these returned an error.

This now seems to be working though:

converted <- mutate(merged, Converted = ifelse(merged$Currency=="
quot;, (merged$Price), (merged$Price/merged[,2])))

And the full code:

Tarantula <- read.csv("Tarantula_Data.csv")

#Getting exchange rates from USD to PLN from 2013 to 2019
cur <- historical_exchange_rates("USD", to = "PLN",
                                 start_date = "2013-01-01", end_date = "2022-03-01")

colnames(cur) <- c('Date','1_USD_to_PLN') #changing column names

#making sure the date columns are formatted as dates
cur$Date <- as.Date(cur$Date, format = "%Y.%m.%d")
Tarantula$Date <- as.Date(Tarantula$Date)

#merging the two datasets together for rows where they share a date
merged <- right_join(cur, Tarantula, by = "Date") 

as.factor(merged$Currency)

converted <- mutate(merged, Converted = ifelse(merged$Currency=="
quot;, (merged$Price), (merged$Price/merged[,2])))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文