obtaining first word in the string [duplicate]
问题 This question already has answers here : Extract first word from a column and insert into new column [duplicate] (3 answers) Closed 2 years ago . I would like to extract the first string from a vector. For example, y<- c('london/hilss', 'newyork/hills', 'paris/jjk') I want to get the string before the symbol"/" i.e., location london newyork paris 回答1: A very simple approach with gsub gsub("/.*", '', y) [1] "london" "newyork" "paris" 回答2: Your example is simple, for a more general case like y<