Skip to content

Instantly share code, notes, and snippets.

@rBatt
Last active February 5, 2016 15:16
Show Gist options
  • Save rBatt/afe78e920321b446fb64 to your computer and use it in GitHub Desktop.
Save rBatt/afe78e920321b446fb64 to your computer and use it in GitHub Desktop.
df <- data.frame(x = rnorm(20, mean=20, sd = 10))
threshold <- 25
replace_val <- 0
df[,"x2"] <- df[,"x"] # make them the same to start
df[df[,"x"] >= threshold, "x2"] <- replace_val # replace values at or above threshold with replacement value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment