-1

I am having this dataset:

title <- c("Make Professional Maps with QGIS and Inkscape | Udemy", "Inkscape desde cero. Crea gráficos vectoriales con Inkscape | Udemy", 
"Logo Design in Inkscape - For Beginners & Beyond | Udemy", "Creating Seamless Tiles in Inkscape | Udemy", 
"Learn Inkscape : Design Logos and Game Arts | Udemy", "Inkscape 101 for Beginners - Design Vector Graphics | Udemy", 
"Design & Create Vector Graphics With Inkscape 2016 | Udemy", 
"Inkscape - Beginner to Pro | Udemy", "Créer un logo avec Inkscape | Udemy", 
"​​​Inkscape: Sıfırdan başlayarak vektörel çizim öğrenin​ | Udemy", 
"Creating 2D Textures in Inkscape | Udemy", "Inkscape fácil - Edición de gráficos vectoriales | Udemy", 
"Inkscape - Criando artes gráficas livremente | Udemy", "【完全版】Inkscape(インクスケープ)でプロ級販促物を作成できる実践講座 | Udemy", 
"Vector Art in Inkscape - Icon Design | Make Vector Graphics | Udemy", 
"Aprenda a criar arte vetorial para jogos 2d com o Inkscape! | Udemy", 
"Inkscape and Bootstrap 3 -> Responsive Web Design! | Udemy")

As you can see, it's a vector containing 17 titles, all of them ending in | Udemy.

How can I remove | Udemy (the vertical bar and the Udemy word)?

I tried with str_replace and grep with no success. Any idea?

antecessor
  • 2,688
  • 6
  • 29
  • 61

3 Answers3

1

One option using sub:

x <- "Make Professional Maps with QGIS and Inkscape | Udemy"
sub("\\| Udemy$", "", x)

This says to target the text | Udemy, but only when it occurs at the very end of the input string.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

The tidyverse approach would be to use the stringr package, for simply removing the text containing udemy, and/or the tidyr package, for separating the data into two columns based on the '|' symbol.

require(tidyverse)

dta <- data_frame(title = title)

dta %>% 
    mutate(new_title = stringr::str_replace(title, "\\| Udemy", "")) # double \\ to interpret | symbol literally

dta %>% separate(title, into = c("course", "provider"), sep = "\\|") 

Both approaches should work. If using the latter the information you want now will be in the course column, but the information you might want to refer to later would be in the provider column. (You may wish to apply str_trim to the latter too to remove the leading whitespace.)

(n.b. remember to save the output if/when you are satisfied with the results.)

JonMinton
  • 1,239
  • 2
  • 8
  • 26
0

use gsub:

gsub(" \\| Udemy", "", title)

which results in:

 [1] "Make Professional Maps with QGIS and Inkscape"                       
 [2] "Inkscape desde cero. Crea gráficos vectoriales con Inkscape"         
 [3] "Logo Design in Inkscape - For Beginners & Beyond"                    
 [4] "Creating Seamless Tiles in Inkscape"                                 
 [5] "Learn Inkscape : Design Logos and Game Arts"                         
 [6] "Inkscape 101 for Beginners - Design Vector Graphics"                 
 [7] "Design & Create Vector Graphics With Inkscape 2016"                  
 [8] "Inkscape - Beginner to Pro"                                          
 [9] "Créer un logo avec Inkscape"                                         
[10] "​​​Inkscape: Sıfırdan başlayarak vektörel çizim öğrenin​"                
[11] "Creating 2D Textures in Inkscape"                                    
[12] "Inkscape fácil - Edición de gráficos vectoriales"                    
[13] "Inkscape - Criando artes gráficas livremente"                        
[14] "【完全版】Inkscape(インクスケープ)でプロ級販促物を作成できる実践講座"
[15] "Vector Art in Inkscape - Icon Design | Make Vector Graphics"         
[16] "Aprenda a criar arte vetorial para jogos 2d com o Inkscape!"         
[17] "Inkscape and Bootstrap 3 -> Responsive Web Design!" 
PavoDive
  • 6,322
  • 2
  • 29
  • 55