2016-10-10 37 views
-3

我有一個數據集,其中有9個不同的屬性coloumns,我必須在每個屬性中找到?。我怎麼找到它?好心幫如何在R大型數據框中找到缺失值(如?)

Age 
? 
45 
67 
89 
? 
56 
78 
+5

我認爲這是最好指定'na.strings =「?」'在閱讀時,即'read.table',這樣它將是NA,並且'class'是t他的專欄將是'數字'而不是'「?」'。對於具體的問題,使用'as.character(df1 $ Age)==「?」'。爲了在整個數據集中找到它,''lapply(df1,「==」,「?」)' – akrun

+1

或''which which(Age ==「?」)''after' – Phann

回答

0

試試這個: -

#so is the dataframe that has the data 
count.q <- function(x) { 
     lengths(regmatches(x, gregexpr("\\?", x))) %>% sum 
} 

apply(so , MARGIN = 2,count.q) 

#count.q gets the count of "?" , and I apply it to the columns of the df. 

對於這個數據 -

Age ID Siblings 
? we 1 
? ? ? 
11 ? 0 
20 ? 0 

我得到這個O/P

Age  ID  Siblings 
     2  3  1 
相關問題