确定列中NA值的数量 [英] Determine the number of NA values in a column

查看:117
本文介绍了确定列中NA值的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算数据框架列中 NA 值的数量。说我的数据框被称为 df ,我正在考虑的列的名称是 col 。我想出的方式如下:

I want to count the number of NA values in a data frame column. Say my data frame is called df, and the name of the column I am considering is col. The way I have come up with is following:

sapply(df$col, function(x) sum(length(which(is.na(x)))))  

这是一个很好的/最有效的方法?

Is this a good/most efficient way to do this?

推荐答案

你过分的考虑了这个问题:

You're over-thinking the problem:

sum(is.na(df$col))

这篇关于确定列中NA值的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆