I have a data frame with these dummy vales values ββand I want to do lm regression on them. One variable is a grouped continuous variable, as shown below.
df <- data.frame("y" = c(10, 11, 12, 13, 14),
"x" = as.factor(c("100-102", "103-105", "106-108", "109-111", "112-114")))
I want to regress y ~ x, one way is to replace the x factors with their average numerical values. This is easy to do using regex.
Another way is to create additional rows and expand the data set so that it looks like this:
data.frame("y" = c(10, 10, 10, 11, 11, 11......),
"x" = c(100, 101, 102, 103, 104, 105......))
Is there a function that will do this?
I am considering first creating additional variables such as x1, x2, x3, and then using the reshape2 package to convert the columns of x to rows.