R Beginners, while learning to write a blog. Daily small applications. R handles Exel.

Source: Internet
Author: User

There are several Excel tables, but the data in each table is different, so read into R for simple processing. The process is simple, basically data filtering, renaming, adding columns, and merging. It also contains considerations for reading tables and storing tables.

#百度
SETWD ("E:/baidu") #设置工作目录
A<-read.table ("20151125.csv", sep= ",", Fill=t,skip=7,header = T) #读取文件, skip Blank
a[,3]<-"Baidu" #修改第三列的内容
B<-read.table ("20151125 (1). csv", sep= ",", Fill=t,skip=7,header = T)
b[,3]<-"Baixingwang"
C<-rbind (A, b) #合并两表
Baidu<-data.frame (c $ date, C $ account, C $ promotion program, C $ show, C $ Click, C $ consumption) #挑选有用变量

Colnames (Baidu) =c ("date", "Account", "Promotion plan", "Show", "click", "Consume") #重新命名
#搜狗
SETWD ("E:/sogou")
D<-read.table ("[Sogou Promotion Service] Custom report-Sogou promotion report -2015-11-25_ full device. csv", sep= ",", Fill=t,header = T)
D<-d[-1,]
Sogou<-data.frame (d$ date, d$ account, d$ promotion plan, d$ impressions, d$ clicks, d$ consumption)
sogou[,2]<-"Sogou"
Colnames (Sogou) =c ("date", "Account", "Promotion plan", "Show", "click", "consume")
#360点睛
SETWD ("e:/360")
E<-read.table ("2015-11-24 promotional program Data report. csv", sep= ",", Fill=t,header = T)
Date <-c (1:length (e$ Promotion plan))
Account <-c (1:length (e$ Promotion program))
E<-data.frame (E, date, account)
e$ date <-"2015/11/24"
e$ account <-"360-point"
Dianjing<-data.frame (e$ date, e$ account, e$ promotion plan, e$ impressions, e$ clicks, e$ Total cost)
dianjing[,2]<-"360"
Colnames (dianjing) =c ("date", "Account", "Promotion plan", "Show", "click", "consume")
#神马 =============
SETWD ("E:/shenma")
Library (XLSX)
F&LT;-READ.XLSX ("Program Promotion report -2015-11-25~2015-11-25#2015-11-26+15-46-38.xlsx", 1,encoding= ' UTF-8 ')
F<-f[,1:6]
Shenma<-data.frame (f)
shenma[,2]<-"Shenma"
Colnames (Shenma) =c ("date", "Account", "Promotion plan", "Show", "click", "consume")
#合并 ============
All<-rbind (Baidu,sogou,dianjing,shenma) #纵向合并
SETWD ("E:/output")
Write.csv (All, "four channels", Row.names = FALSE)
#与四渠道合并
SETWD ("E:/ga")
#quote = "/" "is considered to be delimited only by double quotes, so that Xi ' an can be together
G<-read.table ("Analytics full station data back-up Station page (PLAN) 20151030-20151129.csv", sep= ",", Fill=t,header = T,skip=6,quote = "\" ")
M<-merge (g,all,by= "Promotion program", All=t)
SETWD ("E:/output")
Write.csv (M, "four channel matches. csv")
#读取GA数据 =============================================
#全站pv导航 ============================
SETWD ("E:/ga")
B<-read.table ("Analytics full station data PV nav 20151116-20151122.csv", fill=t,sep= ",", Header = f,skip=7)
B<-b[1: (Which (b$v1== "") [1]-1],]#the data is intercepted according to the length of the first column. Because this table note is special, the above is four columns, the following two columns, two columns of data is not available.
Colnames (b) =c ("source", "Session", "New session Percentage", "User", "Bounce Rate", "page per session", "Average session duration", "Number of users", "PageView")

R Beginners, while learning to write a blog. Daily small applications. R handles Exel.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.