Created
June 13, 2018 06:05
-
-
Save jpzhu/f1ae5b50171ad832fc1f9236d2aa08d4 to your computer and use it in GitHub Desktop.
R note
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> devices=read.table("test.csv",header=TRUE,sep=",") | |
读取数据 | |
> country_table=with(devices,table(country)) | |
计算频率 | |
> as.data.frame(country_table[order(country_table,decreasing=TRUE)]) | |
排序,列显示 | |
> as.data.frame( prop.table(country_table[order(country_table,decreasing=TRUE)])*100) | |
百分比展示 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
设置工作目录
setwd("/Users/jixiaoying/Downloads/");
导入数据
orders=read.table("order.csv",header=TRUE,sep=",")
看数据表结构
str(orders)
head(orders,10)
查看指定列, 以下两个等价
orders[,c(3,15)]
orders[,c("会员名","活动代码")]
过滤指定行
orders[orders$活动代码=="ACT_1787720829_180822105731",]
指定列,指定行
peroids=orders[,c("订购周期","活动代码")]
peroids[peroids$活动代码=="ACT_1787720829_180822105731",]
统计列表数据
with(peroids,table(活动代码))
with(peroids,sort(table(活动代码))) #排序
as.data.frame(with(peroids,sort(table(活动代码)))) ##数据更直观
as.data.frame(with(peroids,sort(table(活动代码),TRUE))) #降序排列
二维表
with(peroids,table(活动代码,订购周期))
组合排序
freqs=as.data.frame(with(peroids,table(活动代码,订购周期)))
freqs[order(freqs$Freq),] ## 根据频率排序
去重
length(unique(orders$订购周期))
length(unique(orders$活动代码))