计算2列之一中存在空白的实例数+ r
我需要测试一个数据框以完成记录 - 要完成记录,必须在两个列中进行条目。在示例df
中,您将看到9个条目中的2个中包含一个行中的空白。
df <- data.frame(a = c(1,2,"",4,5,6,7,"",8,9),
b = c(9,5,2,7,5,"",3,"",6,8))
所需的输出将是2或7
识别完整或相反不完整的记录数量的计数。两者都是空白的实例。
I need to test a dataframe for completion of records - for the records to be complete an entry must be made in both columns. In in the example df
below you will see that 2 of the 9 entries contain blanks in one of the rows.
df <- data.frame(a = c(1,2,"",4,5,6,7,"",8,9),
b = c(9,5,2,7,5,"",3,"",6,8))
The desired output would be a count of 2 or 7
identifying the number of records that are complete or conversely incomplete. Instances where both are blanks would not be considered in the count.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可以是逻辑
矩阵
的sum
- 将'df'转换为逻辑矩阵(df!=''
),获取> rowsums
并检查sum(true
- &gt; 1和false
- &gt; 0)等于列的列数,以返回n1
n1 < /code>并从排行的总数中减去
n2
It could be
sum
of logicalmatrix
- convert the 'df' to logical matrix (df != ''
), get therowSums
and check whether the sum (TRUE
-> 1 andFALSE
-> 0) is equal to number of columns to returnn1
and subtract from the total number of rows to getn2