【发布时间】:2017-03-28 08:05:34
【问题描述】:
我想在字符串中获取属名和种名。 示例:
"He saw a Panthera leo in the savanna"
我希望得到"Panthera leo" 并指定属名。
我尝试使用word 函数(包stringr):
my_sentence<-"He saw a Panthera leo in the savanna"
word(my_sentence,"Panthera",+1)
我知道问题出在“+1”参数上。你有什么线索吗?
也许我应该使用 gsub 函数?
【问题讨论】:
-
就
ind <- grep('Panthera', strsplit(x, ' ')[[1]]); word(x, ind, ind+1) [1] "Panthera leo"