【发布时间】:2023-01-07 06:37:19
【问题描述】:
假设我有两个数据框 A 和 B,它们是这样生成的:
library(dplyr)
# Example Data A
{
set.seed(123)
index = rep(c(1:30),
each = 15*360)
month = rep(c(1:12),
each = 15,
times = 30)
day = rep(c(1:15),
each = 1,
times = 360)
variable_of_interest = runif(n = 15*360*30,
min = 0,
max = 100)
Data_A = as.data.frame(cbind(index,
month,
day,
variable_of_interest))
}
# Example Data B
{
Data_B = Data_A %>% group_by(index,
month) %>% summarise(classification_threshold = mean(variable_of_interest))
}
Data_A 和Data_B 有两个相似的列,index 和month,但行号不同。
我想要的是使用数据帧Data_B的名为classification_threshold的列通过创建一个新列来改变数据帧Data_A,这表明variable_of_interest的相应观察是否有自己的独特阈值(值=1)或低于(值 = 0)。
在这样做时,我想使用列 index 和 month 来识别正确的 classification_threshold 值以与 variable_of_interest 进行比较。
【问题讨论】: