Recode multiple columns using dplyr

后端 未结 5 844
一向
一向 2020-12-11 19:19

I had a dataframe where I recoded several columns so that 999 was set to NA

dfB <-dfA %>%
  mutate(adhere = if_else(adhere==999, as.numeric(NA), adhere         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 19:54

    Now that funs has been depreciated in dplyr, here's the new way to go:

    z <- y %>%
      mutate_if(is.integer, as.numeric) %>%
      mutate_at(vars(y1:y2), list(~recode(.,`999` = NA_real_)))
    

    Replace funs with list and insert a ~ before recode.

提交回复
热议问题