I have a dataframe with columns that contain a messy mix of characters and numbers:
col1 col2 col3 col4 col5
x-x xxx xx* xx- xxx
*y* yyy y*y yy* yyy
What I want is to remove any characters which match a particular regex pattern.
Now I could just do this a column at a time:
data$col3 <- str_remove(data$col3, "[\\-\\*]")
data$col4 <- str_remove(data$col4, "[\\-\\*]")
But this seems like an unnecessarily clunky solution. What I want is to achieve this with a single command within a pipe, something like:
data<- data %>%
str_remove(columns 1,3 and 4, "[\\-\\*]")
I would prefer to identify columns by index position, as the column names are lengthy but necessarily so.