This can be achieved using the mutate
verb from the tidyverse
package. Which in my opinion is more readable. So, to exemplify this, I create a dataset called DT
with a focus on the LocationID
to mimic the problem at hand.
library(tidyverse)
DT <- data.frame('AWC'= c(333, 485, 76, 666, 54),
'LocationID'= c('*Yukon','*Lewis Rich', '*Kodiak', 'Kodiak', '*Rays'))
head(DT)
AWC LocationID
1 333 *Yukon
2 485 *Lewis Rich
3 76 *Kodiak
4 666 Kodiak
5 54 *Rays
In what follows, mutate
allows one to alter the column content, gsub
does the desired substitution (of *
with ""
), keeping the data cleaning flow followable.
DT <- DT %>% mutate(LocationID = gsub("\\*", "", LocationID))
head(DT)
AWC LocationID
1 333 Yukon
2 485 Lewis Rich
3 76 Kodiak
4 666 Kodiak
5 54 Rays
NOTE that \\
is placed before *
as the escape character