简体   繁体   English

如何根据特定条件删除行

[英]How to remove rows based on a particular condition

The data set contains a column with over a 10000 cell phone numbers,it also contains some garbage values with no particular format. 数据集包含一列,其中包含超过10000个手机号码,还包含一些没有特定格式的垃圾值。 How do I retain only the rows with the correct cell phone numbers 如何仅保留具有正确手机号码的行

cell number ............ comment 手机号码............评论

9674544444............... a 9674544444 ...... a

9453453455............... c 9453453455 .............................. c

asd..as23.....................d asd..as23 ..................... d

as sas E2...................d 作为sas E2 .......... d

232dsasd....................,,,,,,,,,,,,,,,23,,,,,231 232dsasd ..................................... 、、、、、、、、、、、、、、、、、、、、、 231


required table 必填表

cell number ............ comment 手机号码............评论

9674544444............... a 9674544444 ...... a

9453453455............... c 9453453455 .............................. c

Like this; 像这样;

df<-read.table(header=T,sep="|",text="cell number|comment
9674544444|a
9453453455|c
asd..as23|d
as sas E2|d
232dsasd|23,,,,,231")

df[grep("[0-9]{10}",df$cell.number),]

#  cell.number comment
#1  9674544444       a
#2  9453453455       c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM