change all negative values in a column of a data frame to zero
You can use an ifelse
command:
df$column <- ifelse(df$column < 0, 0, df$column)
or as @Jilber said in the comments:
df$column[df$column < 0] <- 0
or
within(df, column[column<0] <- 0)