How to copy row from one data.frame in to another [R]

南笙酒味 提交于 2019-12-07 03:22:28

问题


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,]

回答1:


Your example happens to pretty much answer your question. (Try it out!)

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,])


来源:https://stackoverflow.com/questions/10013985/how-to-copy-row-from-one-data-frame-in-to-another-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!