Populate a new column if a value is found in any column

前端 未结 3 1646
花落未央
花落未央 2021-01-25 07:36

I want to check every row in data frame. I need to check all columns in that row to see if it contains a 1, if it does I want to populate another column that summarizes if any

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-25 08:04

    A dplyr way would be

    a1 %>% mutate(imputed_data = ifelse(rowSums(. == 1) != 0, "yes", "no"))
    

提交回复
热议问题