这里是筛选最大值,使用dplyr包,试出两种方法:
> library(dplyr)
> mydt.summary.ttest
Index Line Treatment N Value sd se tt.Pvalue tt.Signf
1 Height Certa CK 3 34.68889 1.3753114 0.7940364 0.392755271
2 Height Certa BC 3 35.81111 1.4945580 0.8628835 0.392755271
3 Height DM70 CK 3 39.17778 2.3412564 1.3517250 0.074737885
4 Height DM70 BC 3 34.96667 1.9470776 1.1241458 0.074737885
5 Height GNN2 CK 3 42.43333 1.1532563 0.6658328 0.019889861 *
6 Height GNN2 BC 3 35.97778 2.7467826 1.5858557 0.019889861 *
7 Height JSN3 CK 3 36.56667 2.7730849 1.6010413 0.899353648
8 Height JSN3 BC 3 36.01111 6.5833404 3.8008933 0.899353648
9 Height LD CK 3 43.94444 0.6850250 0.3954994 0.005312876 **
10 Height LD BC 3 32.96667 3.3857545 1.9547663 0.005312876 **
> mydt.summary.ttest %>% group_by(Index, Line) %>% filter(Value==max(Value))
# A tibble: 14 x 9
# Groups: Index, Line [14]
Index Line Treatment N Value sd se tt.Pvalue tt.Signf
<fct> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
1 Height Certa BC 3 35.8 1.49 0.863 0.393 ""
2 Height DM70 CK 3 39.2 2.34 1.35 0.0747 ""
3 Height GNN2 CK 3 42.4 1.15 0.666 0.0199 "*"
4 Height JSN3 CK 3 36.6 2.77 1.60 0.899 ""
5 Height LD CK 3 43.9 0.685 0.395 0.00531 "**"
> mydt.summary.ttest %>% group_by(Index, Line) %>% slice(which.max(Value))
# A tibble: 14 x 9
# Groups: Index, Line [14]
Index Line Treatment N Value sd se tt.Pvalue tt.Signf
<fct> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
1 Height LD CK 3 43.9 0.685 0.395 0.00531 "**"
2 Height DM70 CK 3 39.2 2.34 1.35 0.0747 ""
3 Height Certa BC 3 35.8 1.49 0.863 0.393 ""
4 Height GNN2 CK 3 42.4 1.15 0.666 0.0199 "*"
5 Height JSN3 CK 3 36.6 2.77 1.60 0.899 ""
其中filter()是按原数据框的顺序输出,slice是依照分组变量(Index, Line)的水平顺序进行输出。