我如何才能只返回匹配以下模式的单词:以空格+“t”或“r”开头,后面直接跟R中的任何数字,包括负数或小数,并且在不满足这些条件的情况下返回NA?
编辑包括可能的十进制数
例如:
testvec <- c("random stuff here","words 10293","random t101rando 101 000","r10000","stuff i-10283","word1 t-12.34 stuff rand10293","random100 u-1000"," r10.0 x ","test x-2930"," T r.1234567","testword120num")
使用上述测试数据的预期结果(testvec):
desired_result <- c(NA,NA,"t101rando",NA,NA,"t-12.34",NA,"r10.0",NA,"r.1234567",NA)
1条答案
按热度按时间ie3xauqp1#
尝试:
有
""
而不是NA
。