如何将行从一个data.frame复制到另一个[R] [英] How to copy row from one data.frame in to another [R]
本文介绍了如何将行从一个data.frame复制到另一个[R]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有两个数据帧x,y。
Id喜欢将数字J从X中复制到Y中。
像
There are two data frames x, y . Id like to copy row with number J from X into Y. Something like
Y[1,] <- X[j,]
推荐答案
例子恰好回答了你的问题。 (尝试一下!)
Your example happens to pretty much answer your question. (Try it out!)
如果要在目标data.frame中替换替换行, / em>一行,请尝试 rbind()
:
If, instead of replacing a row in the target data.frame, you want to add a row to it, try rbind()
instead:
X <- data.frame(name=LETTERS[1:3], value=1:3, stringsAsFactors=FALSE)
Y <- data.frame(name=letters[1:3], value=rnorm(3), stringsAsFactors=FALSE)
X[1,] <- Y[1,]
X <- rbind(X, Y[3,])
这篇关于如何将行从一个data.frame复制到另一个[R]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文