简体   繁体   English

选择包含许多观察结果的列

[英]Select columns with many observations

I have a dataset with lots of observations and lots of variables. 我有一个包含大量观察结果和大量变量的数据集。 But some variables only have real values for a few observations. 但是一些变量只有一些观察结果的真实值。 How can I delete variables that have less than, say, 500 observations? 如何删除少于500个观察值的变量?

I've been trying to figure out a way to do this in the context of dplyr , but select() doesn't seem to work that way. 我一直试图在dplyr的上下文中dplyr一种方法来做到这dplyr ,但是select()似乎不会那样工作。

This doesn't quite make sense either, but it's the direction I've been thinking: 这也不是很有意义,但这是我一直在思考的方向:

dat[,sum(!is.na) > 500]

We can use vapply 我们可以使用vapply

dat[vapply(dat, function(x) sum(is.na(x)) <=500, 0)]

Or with Filter 或搭配Filter

Filter(function(x) sum(is.na(x)) <= 500, dat)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM