删除带有 * 前缀字符串的行 [英] Removing rows with * prefixed string
本文介绍了删除带有 * 前缀字符串的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的数据框
I have a data frame which is as given below
85 P 74 P 70 P 35 P 38 P 54
49 P 35 P 30 P 50 P 30 P 30
104 P 69 P 50 P 70 P 70 P 87
*44 P *35 P 8 F 10 F 9 F *37
*53 P 30 P *40 P 30 P *48 P *73
76 P 86 P 69 P 84 P 66 P 79
110 P 65 P 40 P 57 P 57 P 74
我需要使用 R 删除所有以 * 开头的字符串的行.尝试了 gsub
和 sqldf
但我无法解决它.
I need to remove all the rows that have string starting with * using R. tried gsub
and sqldf
but I couldn't resolve it.
推荐答案
paste
行,grepl
有星号的,去掉不匹配的:
paste
the rows together, grepl
the ones with stars and take those not matched:
DF[!grepl("*", do.call(paste, DF), fixed = TRUE), ]
给予:
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11
1 85 P 74 P 70 P 35 P 38 P 54
2 49 P 35 P 30 P 50 P 30 P 30
3 104 P 69 P 50 P 70 P 70 P 87
6 76 P 86 P 69 P 84 P 66 P 79
7 110 P 65 P 40 P 57 P 57 P 74
这篇关于删除带有 * 前缀字符串的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文