filter id in cluster according another variable in R

前端 未结 2 807
眼角桃花
眼角桃花 2021-01-29 01:17

I have a data with 100 patients and each patient has values from 7 days (1 to 7). How can I select only patients according another variable only in day 1?

df <         


        
2条回答
  •  春和景丽
    2021-01-29 02:04

    When using dplyr:

    library(dplyr)
    df %>% 
      group_by(id) %>% 
      filter(day == 1 & RRT == 0) %>% 
      select(id)
    

    or base R:

    df[df$day == 1 & df$RRT ==0,"id"]
    

提交回复
热议问题