I have got a dataframe df. Is there a way to find the predicted values across groups. For example for below dataframe, I have found the regression equation
df <- structure(list(colA = structure(c(1L, 1L, 1L, 2L, 2L, 2L), .Label = c("A",
"B"), class = "factor"), colB = c(48, 34, 56, 34, 56, 78), colC = c(45,
67, 87, 45, 34, 56)), class = "data.frame", row.names = c(NA,
-6L))
fit <- lmList(colB ~ colC | colA, data = df) # to find regression equation
Now is there a way to find the predicted values by inserting new column (Predicted colB) like below
df
colA colB colC Predicted colB
1 A 48 45
2 A 34 67
3 A 56 87
4 B 34 45
5 B 56 34
6 B 78 56
Predicted colB should have the predicted value in colB based on colC. For example in first row, when colC is 45 what is colB?