首页 文章

当我从数据框中获得一些障碍时,其他观察变为NA

提问于
浏览
0

首先,我从url下载了一个csv文件

fileurl<-"https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv"

week3<-download.file(fileurl,destfile="./week3.csv",method="curl")

然后使用read.csv变成数据框week31 <-read.csv(“week3.csv”,header = TRUE)

enter image description here

之后,当列ACR = 3且AGS = 6时,我需要提取观察结果

agricultureLogical2<-week31[(week31$ACR==3 & week31$AGS==6),]

但结果看起来不太好,不符合每列条件的其他观察值变为NA,为什么呢?

enter image description here

1 回答

  • 0

    使用子集函数,后跟%in%,如果匹配则返回

    agricultureLogical2 <- subset(week31, ACR%in%3 & AGS%in%6 ,]
    

相关问题