I have a data frame such as:
df <- data.frame(col1 = c(1, 2500,1, 1, 1),
col2 = c(12, NA, 8,9, 5),
col3 = c(25, 48, 7, 9, 14))
df
col1 col2 col3
1 1 12 25
2 2500 NA 48
3 1 8 7
4 1 9 9
5 1 5 14
I am hoping to sum the rows only when cell value is above 1, while ignoring NA values, to make a data frame like this:
df_desired <- data.frame(col1 = c(2500),
col2 = sum(12, 8,9, 5),
col3 = sum(25, 48, 7, 9, 14))
df_desired
col1 col2 col3
1 2500 34 103
I have gotten this far:
df_test <- df %>%
summarise_at(vars(contains("col")), sum, na.rm = TRUE)
df_test
col1 col2 col3
1 2504 34 103
I've tried many variations of ifelse with no success. I've so far only found examples of conditional summing across columns and adding a new column.