문제

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

도움이 되었습니까?

해결책

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top