Assume that a dataset has the variables Age, Gender and Height. How to create a linear model based on age that only considers ages between 18 to 21.
This is what i have so far and it works, but I don't know how the && operator works in R.
model1 <- lm(formula = Age > 18 ~ Gender + Height, data = myDataSet)
But when I try adding my second condition the following error occurs:
model2 <- lm(formula = Age > 18 && <21 ~ Gender + Height, data = myDataSet)
ERROR:
Error: unexpected '<' in:
"model2 <- lm(
data=myDataSet, formula= Age > 18 && <"
user11916948 ANSWER:
model3 <- lm(formula = Age>18 & Age<21 ~ Gender + Height, data = myDataSet)
summary(model3)
You could try
age>18 & age<21