慕哥2441251
2019-07-29 14:57
请问怎样用subset()函数构建一个矩阵中某行或某列的子集,调用某行或某列的函数是什么?
> subset(titanic,titanic$Class=="1st") #subset里的第一个参数是矩阵或向量或数据框,第二个参数是判断语句
Class Sex Age Survived Freq
1 1st Male Child No 0
5 1st Female Child No 0
9 1st Male Adult No 118
13 1st Female Adult No 4
17 1st Male Child Yes 5
21 1st Female Child Yes 1
25 1st Male Adult Yes 57
29 1st Female Adult Yes 140
> subset(titanic,titanic$Class=="1st") #第一个参数是数据框或向量或矩阵,第二个参数是判断语句
Class Sex Age Survived Freq
1 1st Male Child No 0
5 1st Female Child No 0
9 1st Male Adult No 118
13 1st Female Adult No 4
17 1st Male Child Yes 5
21 1st Female Child Yes 1
25 1st Male Adult Yes 57
29 1st Female Adult Yes 140
R语言基础
79670 学习 · 262 问题
相似问题