Reputation: 11
I'm new at R and I am trying to remove the year of a film.
movie_title <- c("carrie(2013)", "cars", "lesmiserables(2012)")
For example, here I would like to delete "(2013)" from the title Carrie. So, make "carrie" instead of "carrie(2013)". And apply it to all the similar tiles in the movie_title column in the data frame.
What should I do? Thanks!
Upvotes: 0
Views: 71
Reputation: 12739
You will need to look up regex or regular expressions.
Using base r you can do this:
gsub("\\(\\d{4}\\)", "", movie_title)
With the stringr
package
library(stringr)
str_remove(movie_title, "\\(\\d{4}\\)")
[1] "carrie" "cars" "lesmiserables"
Upvotes: 1