您的位置:首页 > 其它

Jupyter网页版笔记(操作R语言的dplyr包清洗数据)

2017-01-13 10:21 375 查看

这是我的第一个Jupyter网页版笔记

主要是介绍dplyr包清洗asreml中oats的数据

导入dplyr包

library(dplyr)


Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

filter, lag

The following objects are masked from 'package:base':

intersect, setdiff, setequal, union


导入asreml包

library(asreml)


Loading required package: lattice

Licensed to: VSNC
Serial Number: 402567950 Expires: 28-feb-2017 (46 days)


导入数据

data(oats)


head(oats)


BlocksNitrogenSubplotsVarietyWplotsyield
1 0.6_cwt 1 Marvellous1 156
1 0.4_cwt 2 Marvellous1 118
1 0.2_cwt 3 Marvellous1 140
1 0_cwt 4 Marvellous1 105
1 0_cwt 1 Victory 2 111
1 0.2_cwt 2 Victory 2 130

选择一部分数据:用filter函数

选择Blocks=1和Variety=“Marvellous”

filter(oats,Blocks==1,Variety=="Marvellous")


BlocksNitrogenSubplotsVarietyWplotsyield
1 0.6_cwt 1 Marvellous1 156
1 0.4_cwt 2 Marvellous1 118
1 0.2_cwt 3 Marvellous1 140
1 0_cwt 4 Marvellous1 105

选择Blocks==1和Blocks==2

filter(oats,Blocks==1|Blocks==2)


BlocksNitrogenSubplotsVarietyWplotsyield
1 0.6_cwt 1 Marvellous 1 156
1 0.4_cwt 2 Marvellous 1 118
1 0.2_cwt 3 Marvellous 1 140
1 0_cwt 4 Marvellous 1 105
1 0_cwt 1 Victory 2 111
1 0.2_cwt 2 Victory 2 130
1 0.6_cwt 3 Victory 2 174
1 0.4_cwt 4 Victory 2 157
1 0_cwt 1 Golden_rain3 117
1 0.2_cwt 2 Golden_rain3 114
1 0.4_cwt 3 Golden_rain3 161
1 0.6_cwt 4 Golden_rain3 141
2 0.4_cwt 1 Marvellous 1 104
2 0_cwt 2 Marvellous 1 70
2 0.2_cwt 3 Marvellous 1 89
2 0.6_cwt 4 Marvellous 1 117
2 0.6_cwt 1 Victory 2 122
2 0_cwt 2 Victory 2 74
2 0.2_cwt 3 Victory 2 89
2 0.4_cwt 4 Victory 2 81
2 0.2_cwt 1 Golden_rain3 103
2 0_cwt 2 Golden_rain3 64
2 0.4_cwt 3 Golden_rain3 132
2 0.6_cwt 4 Golden_rain3 133

排序,用arrange函数

按照oats的顺序进行排序

arrange(oats)


BlocksNitrogenSubplotsVarietyWplotsyield
1 0.6_cwt 1 Marvellous 1 156
1 0.4_cwt 2 Marvellous 1 118
1 0.2_cwt 3 Marvellous 1 140
1 0_cwt 4 Marvellous 1 105
1 0_cwt 1 Victory 2 111
1 0.2_cwt 2 Victory 2 130
1 0.6_cwt 3 Victory 2 174
1 0.4_cwt 4 Victory 2 157
1 0_cwt 1 Golden_rain3 117
1 0.2_cwt 2 Golden_rain3 114
1 0.4_cwt 3 Golden_rain3 161
1 0.6_cwt 4 Golden_rain3 141
2 0.4_cwt 1 Marvellous 1 104
2 0_cwt 2 Marvellous 1 70
2 0.2_cwt 3 Marvellous 1 89
2 0.6_cwt 4 Marvellous 1 117
2 0.6_cwt 1 Victory 2 122
2 0_cwt 2 Victory 2 74
2 0.2_cwt 3 Victory 2 89
2 0.4_cwt 4 Victory 2 81
2 0.2_cwt 1 Golden_rain3 103
2 0_cwt 2 Golden_rain3 64
2 0.4_cwt 3 Golden_rain3 132
2 0.6_cwt 4 Golden_rain3 133
3 0.2_cwt 1 Golden_rain1 108
3 0.4_cwt 2 Golden_rain1 126
3 0.6_cwt 3 Golden_rain1 149
3 0_cwt 4 Golden_rain1 70
3 0.6_cwt 1 Marvellous 2 144
3 0.2_cwt 2 Marvellous 2 124
4 0.6_cwt 3 Golden_rain2 126
4 0.2_cwt 4 Golden_rain2 82
4 0.2_cwt 1 Victory 3 90
4 0.4_cwt 2 Victory 3 100
4 0.6_cwt 3 Victory 3 116
4 0_cwt 4 Victory 3 62
5 0.6_cwt 1 Golden_rain1 96
5 0_cwt 2 Golden_rain1 60
5 0.4_cwt 3 Golden_rain1 89
5 0.2_cwt 4 Golden_rain1 102
5 0.4_cwt 1 Victory 2 112
5 0.6_cwt 2 Victory 2 86
5 0_cwt 3 Victory 2 68
5 0.2_cwt 4 Victory 2 64
5 0.4_cwt 1 Marvellous 3 132
5 0.6_cwt 2 Marvellous 3 124
5 0.2_cwt 3 Marvellous 3 129
5 0_cwt 4 Marvellous 3 89
6 0.4_cwt 1 Victory 1 118
6 0_cwt 2 Victory 1 53
6 0.6_cwt 3 Victory 1 113
6 0.2_cwt 4 Victory 1 74
6 0.6_cwt 1 Golden_rain2 104
6 0.4_cwt 2 Golden_rain2 86
6 0_cwt 3 Golden_rain2 89
6 0.2_cwt 4 Golden_rain2 82
6 0_cwt 1 Marvellous 3
b492
97
6 0.2_cwt 2 Marvellous 3 99
6 0.4_cwt 3 Marvellous 3 119
6 0.6_cwt 4 Marvellous 3 121

根据Blocks倒序,其它正序

arrange(oats,desc(Blocks))


BlocksNitrogenSubplotsVarietyWplotsyield
6 0.4_cwt 1 Victory 1 118
6 0_cwt 2 Victory 1 53
6 0.6_cwt 3 Victory 1 113
6 0.2_cwt 4 Victory 1 74
6 0.6_cwt 1 Golden_rain2 104
6 0.4_cwt 2 Golden_rain2 86
6 0_cwt 3 Golden_rain2 89
6 0.2_cwt 4 Golden_rain2 82
6 0_cwt 1 Marvellous 3 97
6 0.2_cwt 2 Marvellous 3 99
6 0.4_cwt 3 Marvellous 3 119
6 0.6_cwt 4 Marvellous 3 121
5 0.6_cwt 1 Golden_rain1 96
5 0_cwt 2 Golden_rain1 60
5 0.4_cwt 3 Golden_rain1 89
5 0.2_cwt 4 Golden_rain1 102
5 0.4_cwt 1 Victory 2 112
5 0.6_cwt 2 Victory 2 86
5 0_cwt 3 Victory 2 68
5 0.2_cwt 4 Victory 2 64
5 0.4_cwt 1 Marvellous 3 132
5 0.6_cwt 2 Marvellous 3 124
5 0.2_cwt 3 Marvellous 3 129
5 0_cwt 4 Marvellous 3 89
4 0.4_cwt 1 Marvellous 1 109
4 0.6_cwt 2 Marvellous 1 99
4 0_cwt 3 Marvellous 1 63
4 0.2_cwt 4 Marvellous 1 70
4 0_cwt 1 Golden_rain2 80
4 0.4_cwt 2 Golden_rain2 94
3 0.4_cwt 3 Marvellous 2 121
3 0_cwt 4 Marvellous 2 96
3 0_cwt 1 Victory 3 61
3 0.6_cwt 2 Victory 3 100
3 0.2_cwt 3 Victory 3 91
3 0.4_cwt 4 Victory 3 97
2 0.4_cwt 1 Marvellous 1 104
2 0_cwt 2 Marvellous 1 70
2 0.2_cwt 3 Marvellous 1 89
2 0.6_cwt 4 Marvellous 1 117
2 0.6_cwt 1 Victory 2 122
2 0_cwt 2 Victory 2 74
2 0.2_cwt 3 Victory 2 89
2 0.4_cwt 4 Victory 2 81
2 0.2_cwt 1 Golden_rain3 103
2 0_cwt 2 Golden_rain3 64
2 0.4_cwt 3 Golden_rain3 132
2 0.6_cwt 4 Golden_rain3 133
1 0.6_cwt 1 Marvellous 1 156
1 0.4_cwt 2 Marvellous 1 118
1 0.2_cwt 3 Marvellous 1 140
1 0_cwt 4 Marvellous 1 105
1 0_cwt 1 Victory 2 111
1 0.2_cwt 2 Victory 2 130
1 0.6_cwt 3 Victory 2 174
1 0.4_cwt 4 Victory 2 157
1 0_cwt 1 Golden_rain3 117
1 0.2_cwt 2 Golden_rain3 114
1 0.4_cwt 3 Golden_rain3 161
1 0.6_cwt 4 Golden_rain3 141

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: