r从向量加入表列
我想从另一列中的列中从表中获取向量的相应值。 (请看下面)
示例:
矢量:
v = c('A', 'B', 'C')
表:
# key Value
'C' 3
'A' 1
'B' 2
当我给予矢量v
(a,b,c
)时,我想以良好的顺序获得相应的值1,2,3
。
实际上,向量是数据集的Rownames
,我需要用相应的值替换它。
我正在考虑从dplyr
中使用left_join
函数,但是我需要2个表。
感谢您的帮助
I would like to get the corresponding values of a vector in a table from a column in another column. (just look below)
example:
Vector:
v = c('A', 'B', 'C')
Table :
# key Value
'C' 3
'A' 1
'B' 2
When I give the vector v
(A, B, C
) I want to get back the corresponding values in the good order 1, 2, 3
.
In reality, the vector is the rownames
of a dataset, and I need to replace it with the corresponding values.
I was thinking about using the left_join
function from Dplyr
but I would need 2 tables for this.
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本r
中的一种可能解决方案:使用
dplyr
:A possible solution in
base R
:Using
dplyr
:首先,我投票决定删除 @akrun的答案。
第二是使用与组合 in%中的的替代方案:
First of all I have voted to undelete @akrun's answer.
Second here is an alternative using
which
combined with%in%
: