How to grep a word exactly
问题 I'd like to grep for "nitrogen" in the following character vector and want to get back only the entry which is containing "nitrogen" and nothing of the rest (e.g. nitrogen fixation): varnames=c("nitrogen", "dissolved organic nitrogen", "nitrogen fixation", "total dissolved nitrogen", "total nitrogen") I tried something like this: grepl(pattern= "![[:space:]]nitrogen![[:space:]]", varnames) But this doesn't work. I hope somebody can help me with this task. 回答1: To get the indices that are