[公共数据库] NHANES leisure 业余活动分类处理

PADLEVEL:Activity_level
PADTIMES:times_did_activity_in_past_30_days
PADMETS:MET_score

library(dplyr)
exedata <- tibble(exedata)
exedata
exedata2 <- exedata %>%  # Convert to week
  mutate(times_week=times_did_activity_in_past_30_days / 30 * 7) %>% 
  # distinguish MET_cat  <3   [3,6]   >6
  mutate(MET_cat=if_else(MET_score<3,"<3",if_else(MET_score>6,">6","[3,6]"))) %>%
  #forcats::as_factor(MET_cat) %>% 
  group_by(seqn,MET_cat) %>% 
  summarise(times_week_sum=sum(times_week)) %>% 
  # moderate=[1,5]times + MET [3,6] ; vigorous=[1,3]times+ MET>6
  mutate(Activity_level2=if_else(
    times_week_sum<=5 & times_week_sum>=1 & MET_cat=="[3,6]","moderate",
    if_else(
      times_week_sum<=3 & times_week_sum>=1 & MET_cat==">6","vigorous","insufficient"))) 

exedata3 <-  exedata2 %>% 
  ungroup() %>% 
  select(.,-c(MET_cat,times_week_sum)) %>% 
  mutate(values=1,ID=1:nrow(exedata2)) %>%   
  relocate(ID,.before = 1) %>%
  tidyr::pivot_wider(., names_from = Activity_level2, 
                     values_from = values)

exedata3=as.data.frame(exedata3)
exedata3[which(is.na(exedata3),arr.ind = T)]=0
exedata4 <- exedata3 %>%  
  mutate(ID=forcats::as_factor(seqn)) %>% 
  group_by(seqn) %>% 
  summarise(across(c(moderate:vigorous),~ sum(.x)))
head(exedata4)
table(duplicated(exedata4$seqn))

exedata4 <- exedata4 %>% 
  relocate(insufficient,.before =moderate ) %>% 
  mutate(activity=if_else(vigorous>=1,"vigorous",
         if_else(moderate>=1,"moderate","insufficient")))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值