Reputation: 683
The data set contains a column with over a 10000 cell phone numbers,it also contains some garbage values with no particular format. How do I retain only the rows with the correct cell phone numbers
cell number ............ comment
9674544444............... a
9453453455............... c
asd..as23.....................d
as sas E2...................d
232dsasd....................,,,,,,,,,,,,,,,23,,,,,231
required table
cell number ............ comment
9674544444............... a
9453453455............... c
Upvotes: 0
Views: 193
Reputation: 8691
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
Upvotes: 3