-2

enter image description here

I want to get rid of "-n" at the end of every word in my data frame. Is there any way to do this in R?

sb10
  • 1

2 Answers2

3
gsub('-n$','', 'my_word-n')
[1] "my_word"

#to make this work for the whole data frame you can do 

my_new_df <- sapply(my_old_df, function(x) gsub('-n$','', x))
Mouad_Seridi
  • 2,666
  • 15
  • 27
0

To remove the unwanted string from the end of every word, try

gsub('-n\\b','', df$TextColumn)
G5W
  • 36,531
  • 10
  • 47
  • 80
  • If you want to save the result , you need something like `df$TextColumn = gsub('-n\\b','', df$TextColumn)` – G5W Jun 13 '17 at 15:39