【发布时间】:2014-10-04 01:09:57
【问题描述】:
我想过滤掉列的字符串值中包含“*”的表的行。仅检查该列。
string_name = c("aaaaa", "bbbbb", "ccccc", "dddd*", "eee*eee")
zz <- sapply(tx$variant_full_name, function(x) {substrRight(x, -1) =="*"})
Error in FUN(c("Agno I30N", "VP2 E17Q", "VP2 I204*", "VP3 I85F", "VP1 K73R", :
could not find function "substrRight"
这样,zz 的第四个值应该是 TRUE。
在python中有用于字符串的endswith函数[ string_s.endswith('*') ] R中是否有类似的东西?
另外,因为 '*' 作为一个字符,它意味着任何字符,这是否有问题? grepl 也不起作用。
> grepl("*^",'dddd*')
[1] TRUE
> grepl("*^",'dddd')
[1] TRUE
【问题讨论】:
-
你可以转义
*grepl("\\*",'dddd*')。要查找以*结尾的字符串,您可以使用grepl("\\*$", string_name)