I\'m working on a dataset where one column (Place) consists of a location sentence.
librabry(tidyverse)
example <- tibble(Datum = c(\"Octo
Just split the string on comma and the reverse it.
lapply(strsplit(Place, ","), rev)
[[1]]
[1] " Syria" " Deir Ezzor Governorate"
[3] " 20km south east of Deir Ezzor" "Tabiyyah Jazeera village"
[[2]]
[1] " Syria" " Deir Ezzor Governorate"
[3] "Abu Kamal"
[[3]]
[1] " Syria" " Raqqah governorate"
[3] " north of Raqqah city centre" " al-Tawassiya area"
[5] "شارع القطار al Qitar [train] street"
To get rid of the Arabic characters before splitting, try
gsub("[\u0600-\u06FF]", "", Place)
[1] "Tabiyyah Jazeera village, 20km south east of Deir Ezzor, Deir Ezzor Governorate, Syria"
[2] "Abu Kamal, Deir Ezzor Governorate, Syria"
[3] " al Qitar [train] street, al-Tawassiya area, north of Raqqah city centre, Raqqah governorate, Syria"
Here's a one-liner.
sapply(strsplit(example$Place, ","), function(x) trimws(x[length(x)]))
It will return the string after the last comma, be it Syria or any other.