If looks like there are a few issues here. First, you've stored all your data in separate vectors rent
, income
and black
. You should instead store it in a data frame:
data <- data.frame(rent, income, black)
To limit a data frame based on a logical expression, you can use the subset
function:
data.limited <- subset(data, black == 1)
Finally, you can run your analysis on your limited data frame (presumably without the black
variable):
model3 <- lm(rent~I(income^2)+income, data=data.limited)