[Solved] how to erase several characters in a cell? [closed]


What are other patterns your data has? If it’s always "(B)" you can do

sub("\\(B\\)", "", df$code)
#[1] "1234" "5678" "1234" "5678" "0123"

Or if it could be any character do

sub("\\([A-Z]\\)", "", df$code)

You could also extract only the numbers from Code

sub(".*?(\\d+).*", "\\1", df$code)

You might want to wrap output of sub in as.numeric or as.integer to get numeric/integer output.


We can also use readr

readr::parse_number(df$code)

0

solved how to erase several characters in a cell? [closed]