【发布时间】:2021-04-25 01:16:27
【问题描述】:
我使用下面的代码对两组进行线性回归,以根据年龄预测收入
asd <- data.frame(Age = c(20, 40, 50, 90, 10), Income = c(12, 24, 23, 26, 23), group = c("A","A","A","B","B"))
model <- asd %>% group_by(group) %>% do(model = lm(Income ~ Age, data = .))
但是在上一步之后,我需要计算 2 组的新预测收入
预期输出
Age Income group Predicted Income
1 20 12 A XX ##based on group A coefficients
2 40 24 A YY ##based on group A coefficients
3 50 23 A DD ##based on group A coefficients
4 90 26 B PP ##based on group B coefficients
5 10 23 B RR ##based on group B coefficients
【问题讨论】:
标签: r