【原创】附代码数据
有问题到淘宝找“大数据部落”就可以了
#安装
# install.packages(\ library(\)
library(RODBC) library(DBI)
library(ggplot2) library(RMySQL)
drv <-dbDriver( \ ) l10n_info() ## $MBCS ## [1] TRUE ##
## $`UTF-8` ## [1] FALSE ##
## $`Latin-1` ## [1] FALSE ##
## $codepage ## [1] 936
# Connecting to MySQL:
# Once the RMySQL library is installed create a database connection object.
#这里修改用户名密码和数据库名称
con <-dbConnect(RMySQL::MySQL(), dbname =\, user='root', password='63341498')
#################改变文字编码为GBK方式,否则中文会乱码################### dbSendQuery(con, 'SET NAMES gbk') #向数据库写入或读取数据之前加上此命令 ##
dbListTables(con)
## [1] \ ## [6] \ ## [11] \ ## [16] \
【原创】附代码数据
有问题到淘宝找“大数据部落”就可以了
# Retrieving data from MySQL:
rs =dbSendQuery(con, \)
#
data =fetch(rs ,-1)
# results of this query remain on the MySQL server, to access the results in R we need to use the fetch function. #head of data
#查看数据 #原始数据 head(data)
## tid status seller_nick buyer_nick ## 1 1.048498e+15 TRADE_FINISHED 时间海化妆品旗舰店 tb40425453 ## 2 1.049300e+15 TRADE_FINISHED 时间海化妆品旗舰店 gonow17 ## 3 9.469034e+14 TRADE_FINISHED 时间海化妆品旗舰店 maymaydog ## 4 9.475161e+14 TRADE_FINISHED 时间海化妆品旗舰店 闲看落花_77 ## 5 1.049254e+15 TRADE_FINISHED 时间海化妆品旗舰店 天天悠伴 ## 6 9.475204e+14 TRADE_FINISHED 时间海化妆品旗舰店 xiaotaoqidaisy ## created modified payment iids ## 1 2015-05-13 23:55:45 2015-05-24 10:34:23 78 41878620642 ## 2 2015-05-13 22:12:35 2015-05-24 10:34:21 78 41878620642 ## 3 2015-05-14 00:11:29 2015-05-24 10:34:16 78 41878620642 ## 4 2015-05-13 21:18:02 2015-05-24 10:34:09 78 41878620642 ## 5 2015-05-13 21:25:08 2015-05-24 10:34:02 78 41878620642 ## 6 2015-05-13 21:18:56 2015-05-24 10:34:02 78 41878620642
## ... #处理数据 df=data head(df)
## tid status seller_nick buyer_nick ## 1 1.048498e+15 TRADE_FINISHED 时间海化妆品旗舰店 tb40425453 ## 2 1.049300e+15 TRADE_FINISHED 时间海化妆品旗舰店 gonow17 ## 3 9.469034e+14 TRADE_FINISHED 时间海化妆品旗舰店 maymaydog ## 4 9.475161e+14 TRADE_FINISHED 时间海化妆品旗舰店 闲看落花_77 ## 5 1.049254e+15 TRADE_FINISHED 时间海化妆品旗舰店 天天悠伴 ## 6 9.475204e+14 TRADE_FINISHED 时间海化妆品旗舰店 xiaotaoqidaisy ## created modified payment iids ## 1 2015-05-13 23:55:45 2015-05-24 10:34:23 78 41878620642 ## 2 2015-05-13 22:12:35 2015-05-24 10:34:21 78 41878620642
【原创】附代码数据
有问题到淘宝找“大数据部落”就可以了
## 3 2015-05-14 00:11:29 2015-05-24 10:34:16 78 41878620642 ## 4 2015-05-13 21:18:02 2015-05-24 10:34:09 78 41878620642 ## 5 2015-05-13 21:25:08 2015-05-24 10:34:02 78 41878620642 ## 6 2015-05-13 21:18:56 2015-05-24 10:34:02 78 41878620642
## dim(df) ## [1] 67938 9
df=df[,c(\,\,\,\)]
colnames(df)=c(\ , \ , \,\)
# aggregate(df,by= list(\ df2=aggregate(Amount~ID,data=df,FUN=sum) head(df2)
## ID Amount ## 1 _duoduo_ 1668.00 ## 2 _summer_bye 39.32 ## 3 _talent 600.00 ## 4 _滴水穿石_ 11.30 ## 5 _花事了了了了 91.00 ## 6 _亮子_ 75.98 df3=merge(df,df2,by =\)
head(df3)
## ID Date Amount.x SellerID Amount.y
## 1 _duoduo_ 2016-04-05 14:02:47 339.00 gafuhome家居旗舰店 1668.00
## 2 _duoduo_ 2016-04-06 09:34:04 18.00 gafuhome家居旗舰店 1668.00
## 3 _duoduo_ 2016-04-05 14:17:55 855.00 gafuhome家居旗舰店 1668.00
## 4 _duoduo_ 2016-04-05 14:24:47 456.00 gafuhome家居旗舰店 1668.00
## 5 _summer_bye 2015-05-17 18:33:54 39.32 加油呆子 39.32
## 6 _talent 2016-04-10 02:23:40 100.00 俄速通国际物流 600.00