ackages("tidyr")
##筛选数据,清洗数据
##将过长过大的数据集转换为显示更友好的 tbl_df 类型
tablefilter <- tbl_df(table)
result1<-filter(tablefilter,tablefilter$Price<20.5)
result2<-filter(tablefilter, tablefilter$Num<10 | tablefilter1$Price>1100)
result3<-filter(tablefilter, Month == 1 | Month == 2)
6.计算方差、样本均值、标准差等-apply函数族
apply族函数详解:
博客1:http://blog.csdn.net/wltom1985/article/details/50403720
博客2:http://blog.sina.com.cn/s/blog\_403aa80a010174dj.html
## 计算方差、样本均值、标准差等
## 1代表行,2代表列
例1:xx <- matrix(1:20, 4, 5)
colMeans(xx) #列均值
colSums(xx) #列和
其余大部分都要用到apply()函数
例2:xx <- matrix(1:20, 4, 5)
apply(xx, 2, mean) #列均值,等同于colMeans(xx)
apply(xx, 2, sum) #列和,等同于colMeans(xx),所以矩阵行和列的运算推荐用apply()。
apply(xx, 1, var) #行方差
apply(xx, 2, max) #每列最大值
apply(xx, 2, rev) #每列的数反排列
apply(data,2,sd) #列标准差
7.相关性分析
pearson、spearman相关分析及相关系数矩阵可视化
## cor(mytable) 对mytable所有属性进行相关性分析
##(相关性分析不支持时间戳格式的列以及方差为0的列,应先删去对应列)
corrp<-cor(table1) ## 默认是pearson相关分析
corrs <- cor(table1[4:14],method = 'spearman') ## spearman相关分析
## 相关性分析可视化
## 需要下载corrplot扩展包
install.packages("corrplot")
corrplot(corr = corrp,method="square")
## corrplot(corr = corrs, method = 'color', addCoef.col="grey")
更多关于corrplot扩展包:https://sanwen8.cn/p/139qu99.html
8.取消科学计数法:
options(scipen=200) ##取消科学计数法
9.ggplot扩展包
-见Iris的R语言命令工具箱(2) 明天继续~