我怎么知道具有特定条件的行数?在r
我有此数据框:
d <- structure(list(a = c(1, 66, 58, 0, 91, 37), b = c(44, 0, 75,
11, 0, 32), c = c(0, 81, 0, 53, 25, 13)), class = "data.frame", row.names = c(NA,
-6L))
我需要知道,对于每列,第一个零的位置(行号)。在这种情况下,结果应该
4, 2, 1
如何? THX寻求帮助!
I have this dataframe:
d <- structure(list(a = c(1, 66, 58, 0, 91, 37), b = c(44, 0, 75,
11, 0, 32), c = c(0, 81, 0, 53, 25, 13)), class = "data.frame", row.names = c(NA,
-6L))
I need to know, for each column, the position (row number) of the first zero. In this case the result should be
4, 2, 1
How can I do? Thx for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
max.col
:如果只有正值,也可以做:
You can use
max.col
:If you only have positive values, you can also do:
这是一种方法:
Here is one way:
另一个可能的解决方案:
Another possible solution: