刚刚学习R.
如果data.frameR中有两列,一个是数字,一个是分类,我如何提取一部分data.frame用于?
str(ex0331)
'data.frame': 36 obs. of 2 variables:
$ Iron : num 0.71 1.66 2.01 2.16 2.42 ...
$ Supplement: Factor w/ 2 levels "Fe3","Fe4": 1 1 1 1 1 1 1 1 1 1 ...
Run Code Online (Sandbox Code Playgroud)
基本上,我需要能够分别对这两个因素进行操作; 即我需要能够按Supplement类型(Fe3或Fe4)单独确定铁保留率的长度/平均值/标准差/秒等.
最简单的方法是什么?
我知道这个by()命令.例如,以下内容得到了我需要的一些内容:
by(ex0331, ex0331$Supplement, summary)
ex0331$Supplement: Fe3
Iron Supplement
Min. :0.710 Fe3:18
1st Qu.:2.420 Fe4: 0
Median :3.475
Mean :3.699
3rd Qu.:4.472
Max. :8.240
------------------------------------------------------------
ex0331$Supplement: Fe4
Iron Supplement …Run Code Online (Sandbox Code Playgroud)