subset 函数 选择数据框/向量的子集
作者:互联网
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
标签:subset,name,family,NA,Datafra,子集,select,向量 来源: https://www.cnblogs.com/koujiaodahan/p/15872560.html