1 subset函数,从某一个数据框中选择出符合某条件的数据或是相关的列
(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
- (2)指定显示列
- > selectresult=subset(df1,name=="aa",select=c(age,sex))
- > selectresult
- age sex
- 1 20 f
- (3)多条件查询
- > 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