-1

In a column like this:

data.frame(id = c(1), text = c("keep<U+0E1E>it"))

is there any way to use a gsub in column text to remove character which are inside this <> and remove also this <>

Expected output data.frame(id = c(1), text = c("keep it"))

zx8754
  • 52,746
  • 12
  • 114
  • 209
rek
  • 177
  • 7

1 Answers1

1

Using stringr package:

library(stringr)
library(dplyr)
df <- data.frame(id = c(1), text = c("keep<U+0E1E>it"))
df
  id           text
1  1 keep<U+0E1E>it
df %>% mutate(text = str_remove(text, '<.*>'))
  id   text
1  1 keepit

Using gsub:

gsub('<.*>','',df$text)
[1] "keepit"
Karthik S
  • 11,348
  • 2
  • 11
  • 25