Drop values based on another variable

Foargo9x

New Member
I am trying to create a linear regression model between age and salary for example. I am particularly interested in the younger population so I decided to create another variable

Code:
 age.young <-age[!age >=40]
So now my age.young variable is from 3-39 years old. Now because I want to run the relationship between salary and age.young, I need to create another variable salary.young that correspond to the people between 3-39 years old.

How do I do this? Is this:

Code:
 salary.young <-salary[!age >=40]

staassis

Active Member
You should use brackets, like this:

age.young <-age[!( age >=40 )]

ted00

New Member
that's right

can also make a new data

Code:
newdata = data[data\$age<40,]
and run the analysis on newdata (assumes a dataframe called data that has columns age and salary)