我正在尝试将两个数据帧相乘,但由于出现此错误而无法正常工作:
Error in `[.data.frame`(., select(sewer_and_water, power, roads_and_bridges, :
undefined columns selected
我创建了此数据框:
aggregated_data_mc1_imp <- Estimated_Damage_mc1_reports_data_Imputed_Values %>%
mutate(interval = lubridate::minute(Estimated_Damage_mc1_reports_data_Imputed_Values$time) %/% 5) %>%
group_by(time, interval, sewer_and_water, power, roads_and_bridges, medical, buildings, shake_intensity) %>%
summarise(count = n())
并且我创建了另一个数据框:
agg_var_data_mc1_imp <- aggregate(Estimated_Damage_mc1_reports_data_Imputed_Values[, 1:8], list(Estimated_Damage_mc1_reports_data_Imputed_Values$time), var)
现在,我尝试将它们相乘,并根据时间在这两个相乘中创建一个新的数据框。
这样我就有了一个新的数据框:
使每行根据时间相乘。我在图片中添加了一些计算,但未对所有数据点进行计算。但我希望你能明白。
我尝试过的是这个
df3 <- agg_var_data_mc1_imp %>% select(sewer_and_water, power, roads_and_bridges, medical, buildings, shake_intensity)[match(aggregated_data_mc1_imp$time, agg_var_data_mc1_imp$Group.1,)] * aggregated_data_mc1_imp[-1]
但由于出现此错误而无法正常工作
Error in `[.data.frame`(., select(sewer_and_water, power, roads_and_bridges, :
undefined columns selected
如果您可以提出一种在R中执行此操作的方法,或者没有,那么您也可以在python中提出一种方法。
编辑:
structure(list(Group.1 = structure(c(1586131200, 1586131500,
1586131800, 1586132100, 1586132400, 1586132700, 1586133000, 1586133300,
1586133600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
sewer_and_water = c(9.71428571428571, 9.84090909090909, 11,
7.14285714285714, 25.5833333333333, 8.55357142857143, 19,
12.8095238095238, 12.6944444444444), power = c(7.35714285714286,
11.8181818181818, 7.61818181818182, 18.1428571428571, 2.66666666666667,
9.98214285714286, 14.3333333333333, 18.4761904761905, 7.27777777777778
), roads_and_bridges = c(11.125, 13.7272727272727, 18.2545454545455,
11.5714285714286, 12, 10.125, 1.33333333333333, 10.9047619047619,
12.5), medical = c(5.64285714285714, 12.5151515151515, 13.7636363636364,
14.8095238095238, 10, 10.8392857142857, 24.3333333333333,
10.9047619047619, 8.36111111111111), buildings = c(8.26785714285714,
14.969696969697, 11.6545454545455, 10.6190476190476, 21.6666666666667,
6.83928571428571, 3, 8.57142857142857, 7.25), shake_intensity = c(0.267857142857143,
0.204545454545455, 0.254545454545455, 2.57142857142857, 0.25,
0.285714285714286, 0.333333333333333, 5.14285714285714, 0.277777777777778
), location = c(45.2678571428571, 23, 35.0181818181818, 7.28571428571429,
42, 31.125, 70.3333333333333, 33.5714285714286, 27.5), estimated_damage = c(0.6529805,
0.66033475, 0.249612054545455, 1.3670839047619, 0.214479583333334,
0.290629267857143, 1.86052233333333, 0.777290333333334, 0.616270277777778
)), .Names = c("Group.1", "sewer_and_water", "power", "roads_and_bridges",
"medical", "buildings", "shake_intensity", "location", "estimated_damage"
), row.names = c(NA, 9L), class = "data.frame")