我有一个?_的大比例尺数据帧吗?值,其维度为501行和42844列。通过使用下面的代码,我已经用NA替换了它们:
data[data == "?_?"] <- NA所以我现在有NA值了,我想从Data.frame中省略这些值,但是有些事情变坏了.当我按下命令时:
data_na_rm <- na.omit(data)因此,我得到一个0,42844的对象。
dim(data_na_rm) #gives me 0 42844
data_na_rm[1,2] #gives me NA
data_na_rm[5,3] #gives me NA
############################
data_na_rm[2] #gives me the title of the second column
data_na_rm[5] #gives me the title fo the fifth我要做什么??我在这件事上花了好几个小时。如果有人能花点时间来帮助我,我将不胜感激。
发布于 2016-11-18 02:32:21
就像JackStat在评论中所说的那样,您可能在每一行中都有NAs。也许你应该测试一下?:
# Some Data. All rows have an NA but not all columns
df <- data.frame(col1 = c(NA, 2, 3, 4),
col2 = c(1, NA, 3, 4),
col3 = c(1, 2, NA, 4),
col4 = c(1, 2, 3, NA),
col5 = c(1, 2, 3, 4))
# test whether an NA is present in each row
apply(df, 1, function(x) {sum(is.na(x)) > 0})
[1] TRUE TRUE TRUE TRUE这将帮助您找到哪些列贡献最大的NAs。它总结了国家统计局的数量:
apply(df, 2, function(x) {sum(is.na(x))})
col1 col2 col3 col4 col5
1 1 1 1 0https://stackoverflow.com/questions/40667942
复制相似问题