###导入数据
load("D:\\R\\futures_user_2.dat")
####提取需要画图的数据
a=futures_user_2[,c(1,2,5)]
####对部分错误的数据进行修改
a$province[which(a$province=="广西桂林")]<-"广西"
######去除空置和null
b=a[-which(is.na(a$province)),]
unique(b$province)
c=b[-which(b$province=="null"),]
unique(c$province)
head(c)
####如果有==0的,需要剔除
d=c[-which(c$avg_return_rate==0),]
#####进行分类
c$class=ifelse(c$avg_return_rate>0,"盈利","亏损")
######用tapply进行分组计算
d=tapply(c$id,list(c$province,c$class),length)
d=as.data.frame(d)
###提取省份名称(tapply无法选取分类组的名称,没找到原因)
e=unique(c$province)
f=e[order(e)]
d$省份=f
####将空值赋值为0
d$亏损[which(is.na(d