如何在数据框架的一列中替换Na值,并用不同的数据框中的列中的值替换值?
如何将“示例”中的NA值替换为“示例2”中的相应值?因此,7将代替第一个NA,而8将代替第二个NA等。我的数据大得多,因此我将无法单独重命名多个NAS的值。谢谢
example <- data.frame('count' = c(1,3,4,NA,8,NA,9,0,NA,NA,7,5,8,NA))
example2 <- data.frame('count' = c(7,8,4,6,7))
How do I replace the NA values in 'example' with the corresponding values in 'example 2'? So 7 would take the place of the first NA and 8 would take the place of the second NA etc. My data is much larger so I would not be able to rename the values individually for the multiple NAs. Thanks
example <- data.frame('count' = c(1,3,4,NA,8,NA,9,0,NA,NA,7,5,8,NA))
example2 <- data.frame('count' = c(7,8,4,6,7))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基于
替换
的另一个可能的解决方案:Another possible solution, based on
replace
:您可以尝试:
这将为您提供:
编辑:,由于您的数据范围内的一列可能不止一列,因此您应该使用:
You can try with :
Which will give you :
EDIT: Since you probably have more than just one column in your dataframes, you should use :
使用
的另一个选项
要检查Na值的索引:输出:
Another option using
which
to check the index of NA values:Output: