I would like to find a solution for the following problem, hope someone can help me. I have a dataframe with over 2000 columns and I need just two of them. First I need to check if the sums (df$values1 + df$values2.) of the two columns are than 15. Now I would like to have a result column: If yes: 15 If no: sum up the values of the first to the second column, so that df$values1 + df$values2.
I tried to get an result with the following, but it doesn't work:
df$result <- apply(df[which(colnames(df)=="values1")],2,
function(x) {ifelse(df[which(colnames(df)=="values2")]+x >= 15, 15, df[which(colnames(df) == "values2")] + x)
}
)
Thanks!