I have a df as follows which has 20 people across 5 households. Some people within the household have missing data for whether they have a med_card or not. I want to give th
This is late, but if are working on a numeric column, try this:
require(data.table) setDT(df)[,'record_year':=mean( med_card,na.rm = T),by = c('hhold_no')]