In R, I want to loop over items to replace in a column.
the input into the function is a list of items and I want to return the list after removing any and all items within itemsToBeRemoved list.
removePunctuation <- function(punctuationObject){
itemsToBeRemoved <- list(".", ",", ";", ":", "'", "!", "#", "-", "--")
objectApplyTo <- punctuationObject
for (itemToReplace in itemsToBeRemoved){
resultObject <- gsub("itemToReplace", "", objectApplyTo, fixed=TRUE)
return(resultObject)
}
}
I expect all instances of ".", ",", ";", ":", "'", "!", "#", "-", "--" to be removed from a list of character elements.