dplyr::mutate (assign na.rm =TRUE)

前端 未结 3 1203
野性不改
野性不改 2021-01-13 07:23

I have a data.frame that has 100 variables. I want to get the sum of three variables only using mutate (not summarise).

If there is NA in a

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 07:44

    rowwise() is my go-to function. It's like group_by() but it treats each row as an individual group.

    df %>% rowwise() %>% mutate(Sum = sum(c(var1, var2, var3), na.rm = TRUE))
    

提交回复
热议问题