如何在大数据帧中删除丢失的数据 [英] how deleted the missing data in large data frame
本文介绍了如何在大数据帧中删除丢失的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很大的data.frame,如果 code1
和 code2
和 code3
丢失,我将删除
I have a large data.frame, if the code1
and code2
and code3
are missing then I will deleted
DATE BIRTHDAY ID code1 code2 code3 ID_SEX
19970406 19501022 1 32 4 2 F
19980508 19501022 1 F
19980508 19501022 1 2 56 43 F
19990805 19500502 2 23 56 M
20000321 19500502 2 4 M
20060715 19500322 3 F
我想要这个
DATE BIRTHDAY ID code1 code2 code3 ID_SEX
19970406 19501022 1 32 4 2 F
19980508 19501022 1 2 56 43 F
19990805 19500502 2 23 56 M
20000321 19500502 2 4 M
id可以通过rep。
the id may by rep.
推荐答案
假设你打电话给你的data.frame mydata
:
Assuming you call your data.frame mydata
:
mydata[
apply( mydata[ c("code1", "code2", "code3") ], 1, function(x){
! all( is.na( x ) )
}),
]
编辑
考虑到Justins的评论,以防您的代码列不是数字,但类型为 character
或因素
,而缺少的值实际上不是 NA
而是空字符串(),您可以使用
Considering Justins comment and just in case your code columns are not numeric but of type character
or factor
and the missing values are actually not NA
s but empty strings (""
) you could capture the desired rows with
mydata[
apply( mydata[ c("code1", "code2", "code3") ], 1, function(x){
any( x != "" )
}),
]
这篇关于如何在大数据帧中删除丢失的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文