R:如何用不同数据框中的另一列替换一列?
我想将 ped
数据帧的 第 6 列 替换为 bipolar_ctl
数据帧中的 Phenotype
列。
我的尝试:
dplyr::mutate_at(ped, vars(-one_of("bipolar_ctl$Phenotype")))
I want to replace the 6th column of the ped
dataframe with the Phenotype
column from bipolar_ctl
dataframe.
My attempt:
dplyr::mutate_at(ped, vars(-one_of("bipolar_ctl$Phenotype")))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用基础
R
,Using base
R
,另一种选择是:
another option would be:
注意两个数据集中可能出现不同的行顺序,这在较长的脚本中很容易发生。
您可以使用
match
轻松考虑这一点:或者使用
merge
。或者使用
stopifnot
。数据(具有不同的 ID 顺序):
Beware of the possible occurrence of different row orders in the two data sets, which easily may happen in a long script.
You can easily take this into account by using
match
:Or, use
merge
.Alternatively use a
stopifnot
.Data (with different id order):