subset函数,从某一个数据框中选择出符合某条件的数据或是相关的列
(1)单条件查询
(2)指定显示列
(3)多条件查询
(1)单条件查询
- > selectresult=subset(df1,name=="aa")
- > selectresult
- name age sex
- 1 aa 20 f
- > df1
- name age sex
- 1 aa 20 f
- 2 bb 29 m
- 3 cc 30 f
- > selectresult=subset(df1,name=="aa",select=c(age,sex))
- > selectresult
- age sex
- 1 20 f
- > selectresult=subset(df1,name=="aa" & sex=="f",select=c(age,sex))
- > selectresult
- age sex
- 1 20 f
- > df1
- name age sex
- 1 aa 20 f
- 2 bb 29 m
- 3 cc 30 f