使用dplyr计算,每列中NA的百分比 [英] Calculate using dplyr, percentage of NA'S in each column
本文介绍了使用dplyr计算,每列中NA的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框,其中一些列缺少值.有没有办法(使用 dplyr)有效地计算每列缺失的百分比,即 NA.寻求像 colSum 等价物.所以我不必单独计算每一列缺失的百分比?
I have a data frame with some columns with missing values. Is there a way (using dplyr) to efficiently calculate the percentage of each column that is missing i.e. NA. Sought of like a colSum equivalent. So I dont have to calculate each column percentage missing individually ?
推荐答案
首先,我为你创建了一个测试数据:
First, I created a test data for you:
a<- c(1,NA,NA,4)
b<- c(NA,2,3,4)
x<- data.frame(a,b)
x
# a b
# 1 1 NA
# 2 NA 2
# 3 NA 3
# 4 4 4
然后你可以使用 colMeans(is.na(x))
:
colMeans(is.na(x))
# a b
# 0.50 0.25
这篇关于使用dplyr计算,每列中NA的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文