获取字符串中的第一个单词 [英] obtaining first word in the string
本文介绍了获取字符串中的第一个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从向量中提取第一个字符串.例如,
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
推荐答案
gsub
gsub("/.*", '', y)
[1] "london" "newyork" "paris"
这篇关于获取字符串中的第一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文