根据第一个双精度向量对第二个双精度向量重新排序 [英] reorder second double vector according to first double vector

查看:148
本文介绍了根据第一个双精度向量对第二个双精度向量重新排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与以下内容有关: r-根据第一个对第二个向量进行重新排序.当向量不是从1开始并且具有类double时,那里的解决方案不能解决问题.

This question relates to: r - reorder second vector according to first. The solution there does not solve the problem when vectors don't start from 1 and have class double.

给出以下两个向量:

a <- c(5.1, 7.2, 4.3, 8.4)
b <- c(4.3, 7.2, 8.4, 5.1)

需要创建第三个向量c,该向量将给出需要重新排序向量b的顺序,使其与a相同.在这种情况下:

a third vector c needs be created that would give the order in which vector b needs be reordered for it to be in the same order as a. In this case:

c <- c(4, 2, 1, 3)

这样:

> b[c] == a
[1] TRUE TRUE TRUE TRUE

推荐答案

这不是c <- match(a, b)吗?

这可以安全地工作

  • 一个向量是另一个向量的置换(也就是说,如果两个向量都经过排序,则它们是相同的);
  • 没有绑定值(也就是说,没有一个值出现多次).

您的应用程序似乎满足了这些要求,但对其他读者指出来还是件好事.

Looks like your application meets these requirement, but it is still good for me to point it out for other readers.

这篇关于根据第一个双精度向量对第二个双精度向量重新排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆