R - Simultaneously Replacing a set of columns using 'gsub'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
head(diamonds,10) | |
colList <- c("cut", "clarity") #list of columns to replace. Can also be column numbers. | |
rowstoReplace <- 1:10 | |
lapply(colList, function(colname){gsub("I", ".", diamonds[rowstoReplace, colname])}) | |
#lapply gives it one column name at a time... | |
#Use a comma instead of rowstoReplace if you want all rows changed. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment