Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top