这是我的第一个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)
| Blocks | Nitrogen | Subplots | Variety | Wplots | yield |
---|
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 |
选择一部分数据:用filter函数
选择Blocks=1和Variety=“Marvellous”
filter(oats,Blocks==1,Variety=="Marvellous")
| Blocks | Nitrogen | Subplots | Variety | Wplots | yield |
---|
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 |
选择Blocks==1和Blocks==2
filter(oats,Blocks==1|Blocks==2)
| Blocks | Nitrogen | Subplots | Variety | Wplots | yield |
---|
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_rain | 3 | 117 |
1 | 0.2_cwt | 2 | Golden_rain | 3 | 114 |
1 | 0.4_cwt | 3 | Golden_rain | 3 | 161 |
1 | 0.6_cwt | 4 | Golden_rain | 3 | 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_rain | 3 | 103 |
2 | 0_cwt | 2 | Golden_rain | 3 | 64 |
2 | 0.4_cwt | 3 | Golden_rain | 3 | 132 |
2 | 0.6_cwt | 4 | Golden_rain | 3 | 133 |
排序,用arrange函数
按照oats的顺序进行排序
arrange(oats)
| Blocks | Nitrogen | Subplots | Variety | Wplots | yield |
---|
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_rain | 3 | 117 |
1 | 0.2_cwt | 2 | Golden_rain | 3 | 114 |
1 | 0.4_cwt | 3 | Golden_rain | 3 | 161 |
1 | 0.6_cwt | 4 | Golden_rain | 3 | 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_rain | 3 | 103 |
2 | 0_cwt | 2 | Golden_rain | 3 | 64 |
2 | 0.4_cwt | 3 | Golden_rain | 3 | 132 |
2 | 0.6_cwt | 4 | Golden_rain | 3 | 133 |
3 | 0.2_cwt | 1 | Golden_rain | 1 | 108 |
3 | 0.4_cwt | 2 | Golden_rain | 1 | 126 |
3 | 0.6_cwt | 3 | Golden_rain | 1 | 149 |
3 | 0_cwt | 4 | Golden_rain | 1 | 70 |
3 | 0.6_cwt | 1 | Marvellous | 2 | 144 |
3 | 0.2_cwt | 2 | Marvellous | 2 | 124 |
… | … | … | … | … | … |
4 | 0.6_cwt | 3 | Golden_rain | 2 | 126 |
4 | 0.2_cwt | 4 | Golden_rain | 2 | 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_rain | 1 | 96 |
5 | 0_cwt | 2 | Golden_rain | 1 | 60 |
5 | 0.4_cwt | 3 | Golden_rain | 1 | 89 |
5 | 0.2_cwt | 4 | Golden_rain | 1 | 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_rain | 2 | 104 |
6 | 0.4_cwt | 2 | Golden_rain | 2 | 86 |
6 | 0_cwt | 3 | Golden_rain | 2 | 89 |
6 | 0.2_cwt | 4 | Golden_rain | 2 | 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))
| Blocks | Nitrogen | Subplots | Variety | Wplots | yield |
---|
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_rain | 2 | 104 |
6 | 0.4_cwt | 2 | Golden_rain | 2 | 86 |
6 | 0_cwt | 3 | Golden_rain | 2 | 89 |
6 | 0.2_cwt | 4 | Golden_rain | 2 | 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_rain | 1 | 96 |
5 | 0_cwt | 2 | Golden_rain | 1 | 60 |
5 | 0.4_cwt | 3 | Golden_rain | 1 | 89 |
5 | 0.2_cwt | 4 | Golden_rain | 1 | 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_rain | 2 | 80 |
4 | 0.4_cwt | 2 | Golden_rain | 2 | 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_rain | 3 | 103 |
2 | 0_cwt | 2 | Golden_rain | 3 | 64 |
2 | 0.4_cwt | 3 | Golden_rain | 3 | 132 |
2 | 0.6_cwt | 4 | Golden_rain | 3 | 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_rain | 3 | 117 |
1 | 0.2_cwt | 2 | Golden_rain | 3 | 114 |
1 | 0.4_cwt | 3 | Golden_rain | 3 | 161 |
1 | 0.6_cwt | 4 | Golden_rain | 3 | 141 |