subset(数据框,条件) 按条件选择子集
Datafra<-data.frame(name=c(1,2,4,NA,4,5,7),family=c("xiao","ming",NA,NA,"zhou","zheng","li")) Datafra
subset(Datafra,name>=1)
subset(Datafra,name>=1 & family !="NA") #允许逻辑符
> subset(Datafra,name>=1 & family !="NA",select = name)
subset(Datafra,name>=1 & family !="NA",select = 1) #搭配select 选择列名/列索引
df<-subset(Datafra,select = -c(name)) # 减号去除某列
还可以从向量中依条件选择元素 如subset(vec,vec>2) ,默认去除NA