R解析文件--找出常用地址

解析文件–找出常用地址

如何使用R来解析?
文件数据为三列,电话,地址,访问时间
要求输出每个电话的常用地址

  • 找出每个手机号的所有地址
    因为是字符串,不能用大小等于
    因为手机号是有序排列,利用match就可以
x<-read.csv("C:/Users/elenawang/Desktop/csv_res.csv",header=F)
mobi<-x$V1
loc<-x$V2
l<-length(mobi)
b<-levels(factor(mobi))
lb<-length(b)
max<-match(b[2],mobi)-1
local0=loc[1:max]
c<-levels(factor(local0))
data<-data.frame(mobile=b[1],location=c)
for(i in 2:(lb-1)){
  min=match(b[i],mobi)
  max=match(b[i+1],mobi)-1
  local1=loc[min:max]
  c=levels(factor(local1))
  data1<-data.frame(mobile=b[i],location=c)
  data<-rbind(data,data1)
}
print(b[lb])
min=match(b[lb],mobi)
local2=loc[min:l]
c<-levels(factor(local2))
data2<-data.frame(mobile=b[lb],location=c)
data<-rbind(data,data2)
write.csv(data, file = "C:/Users/elenawang/Desktop/res_loc.csv", row.name
```p/res_loc.csv", row.name
  • 关联做频率

利用grep

可以得到所有地址的一个频率,根据设定阈值,取出常用地址
进一步改进:
添加10天内常用地址,一个月内常用地址,两个月内常用地址。

猜你喜欢

转载自blog.csdn.net/changzoe/article/details/78794809