i need create dichtomized variable based on 2 factors (one hopes it's possible). let's have data: d <- data.frame ( agegroup = c(2,1,1,2,3,2,1,3,3,3,3,3,1,1,2,3,2,1,1,2,1,2,2,3) , gender = c(2,2,2,2,2,2,1,2,1,1,1,2,1,1,2,2,1,1,1,1,2,1,1,1) , hourwalking = c(0.3,0.5,1.1,1.1,1.1,1.2,1.2,1.2,1.3,1.5,1.7,1.8,2.1,2.1,2.2,2.2,2.3,2.4,2.4,3,3.1,3.1,4.3,5) ) i create binary (lowwalkhrs) using gender- , agegroup-specific median (e.g., when agegroup = 1 , gender = 1, median = 2.1 (median found using excel)). lowwalkhrs added variable in dataset, output be: agegroup gender hourwalk lowwalkhrs 2 2 0.3 1 1 2 0.5 1 1 2 1.1 0 2 2 1.1 1 3 2 1.1 1 2 2 1.2 0 1 1 1.2 1 .... 3 1 5 0 i have rather large dataset (~10k observations),...