To select a subset of a variable based on the categories of other variables or condition in further analysis, we can do with the following code
For example we need to get the subset of variable age based on the gender
age = c(45,50,60)
gender = c("F", "M","F")
maleage <- age[gender == "M"]
femaleage <- age[gender == "F"]