R语言累计求和,生成时间列,拼接字符串,批量导入导出

累计求和
w<-read.table("E:/bs/sys/每天点击次数的统计(补0)/nucmail.txt",sep="")
head(w)
w1<-rowSums(w[,c(2:236)]) 
w<-w$V1
length(w)
length(w1)
x=data.frame(w,w1)
write.table (x, file ="E:/bs/sys/nucmail.txt", sep =" ", row.names =F, col.names =F, quote =F)


生成时间列
rm(list=ls())
w<-read.table("E:/bs/sys/每天点击次数的统计(补0)/wymail.txt",sep="")
head(w)
w1<-colSums(w[,c(2:236)])
write.table (w1, file ="E:/bs/sys/wymail.txt", sep =" ", row.names =F, col.names =F, quote =F)

d=seq(as.Date("2000/1/1"),as.Date("2000/1/5"), by="day") #按日生产从XXXX.XX.XX到XXXX.XX.XX时间
d[-c(1,2,3)]  去掉第几个数据
length(d)
which(d == "2014-07-31")  返回满足条件的索引
d=d[-202] 

拼接字符串 批量导入导出
d=seq(as.Date("2013/12/14"),as.Date("2014/8/5"), by="day")
x<-c("dban","kx","nucmail","qqmail","qzone","rr","sinamail","sinawb","tencentwb","wymail")
for (i in x){
data<-paste("E:/bs/sys/每天点击次数的统计(补0)/",i,".txt",sep="")#拼接字符串
w<-read.table(data,sep="")
w1<-colSums(w[,c(2:236)])
#print(data)
data<-paste("E:/bs/sys/",i,".txt",sep="")
#print(data)
sc=data.frame(d,w1)
write.table (sc, file =data, sep =" ", row.names =F, col.names =F, quote =F)
}

你可能感兴趣的:(R)