R 创建NA行的子集数据

R 创建NA行的子集数据,r,R,我一直在处理这个大型数据集(19个变量,包含int、字符串和float的任意组合,包含完整的观察值和包含空变量的观察值)。我已经根据日期将它们分为不同的数据帧,并且得到了一些意想不到的结果。我迄今为止的工作: # reading in data; at this point there are no rows that are completely # full of na values Data <- read.csv("Data.csv", stringsAsFactors

我一直在处理这个大型数据集(19个变量,包含int、字符串和float的任意组合,包含完整的观察值和包含空变量的观察值)。我已经根据日期将它们分为不同的数据帧,并且得到了一些意想不到的结果。我迄今为止的工作:

# reading in data; at this point there are no rows that are completely
# full of na values
     Data <- read.csv("Data.csv", stringsAsFactors = FALSE)

# removing data I don't want to look at; I'm sure this isn't the
# most efficient way to do this but it works
     Data2 <- Data[!(Data$Event.Clearance.Group=="TRAFFIC RELATED CALLS") & 
                      !(Data$Event.Clearance.Group=="FALSE ALARMS") &
                      !(Data$Event.Clearance.Group=="FALSE ALACAD") &
                      !(Data$Event.Clearance.Group=="HARBOR CALLS") &
                      !(Data$Event.Clearance.Group=="NULL"),]

# reformatting the date into new col to easily subset
     Data2$Date <- as.Date(as.character(Data2$Event.Clearance.Date), "%m/%d/%Y")

# Subsetting Data into years; after I do this the subsets suddenly have 
# tons of NA values. I do this for each year from 2011 - 2015
     Data2011 <- Data2[Data2$Date >= as.Date("2011-01-01") & 
                      Data2$Date <as.Date("2012-01-01"),]
#读取数据;此时,没有完全相同的行
#充满na值

Data您的Data2$Date是否有NA值? 结果如何

    sum(is.na(Data2$Date >= as.Date("2011-01-01") & 
                          Data2$Date <as.Date("2012-01-01")))
sum(is.na(Data2$Date>=截止日期(“2011-01-01”)&

Data2$Date您的Data2$Date是否有NA值? 结果如何

    sum(is.na(Data2$Date >= as.Date("2011-01-01") & 
                          Data2$Date <as.Date("2012-01-01")))
sum(is.na(Data2$Date>=截止日期(“2011-01-01”)&

Data2$Date可能会使用运行良好的
myYearList,谢谢。显然,我只是用我的其他方法每次生成14198个空行……但我的问题仍然是,为什么会生成这些空行?可能会使用运行良好的
myYearList,谢谢。显然,我只是每次使用我的另一个方法…我的问题仍然存在,为什么要生成这些空行?