填充r:在X列中填充Na,并带有来自同一ID(Y列)对应关系的值
我有这个数据集(如下所示)
db< - as.data.frame(cbind(c(c(1,2,2,2,3,3,3,4,4,4,4,4,5,5),C ('a','b',na,na,'i',na,'d',na,na,na))))
我想从ID列中用相同的correpondance填充v2 na V1。 最后,我希望这个结果
db< - as.data.frame(cbind(c(1,2,2,2,3,3,4,4,4,4,4,4,5,5),c('a' ,'b','b','i','i','d','d','d',d',na,na))))
我试图用唯一 id
db_aux< - as.data.frame(cbind(c(1,2,3,4),c('a'','b','i','i','d'))))
但是我想是应用
函数才能填写剩下的内容,但我不觉得如何指示相应的索引。
I´ve got this dataset (something like below)
db <- as.data.frame(cbind(c(1,2,2,3,3,4,4,4,5,5),c('a','b',NA,NA,'i',NA,'d',NA, NA, NA)))
I´d like to fill the V2 NA with same correpondance from ID column V1.
At the end I expect this result
db <- as.data.frame(cbind(c(1,2,2,3,3,4,4,4,5,5),c('a','b','b','i','i','d','d','d', NA, NA)))
I´ve tried to make a list with unique
IDdb_aux <- as.data.frame(cbind(c(1,2,3,4),c('a','b','i','d')))
but I guess it´s necessary an apply
function to fill in what´s left but i´m not figuring how to indicate the corresponding indexation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从
tidyr
中使用填充
,而该方向是更新或倾斜的。You can use
fill
fromtidyr
with the direction being updown or downup.