简体   繁体   中英

How do I calculate the sum of the frequency of a variable with dplyr

I'm working with the EU SILC data and want to create a variable for the number of kids in a household. I already joined the household register and household data with the personal data (dhp).

I tried this code dhpr <- left_join(dhp, perreg %>% group_by(idh) %>% summarise(nkids=sum(RX010<14)), by='idh') where RX010 is the age on the date of the interview. If I do this, I don't get the number of children but instead the age of the oldest child in the household, for example: number of kids

What am I doing wrong?

dhpr <- left_join(dhp, perreg %>% group_by(idh) %>% 
  summarise(nkids=sum(ifelse(RX010<14,1,0))), by='idh')

might help. But since you did not supply a working example, it is a shot in the dark.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM