首页 \ 问答 \ 基于不完整向量对数据帧中的列进行排序(ordering columns in dataframe based on incomplete vector)

基于不完整向量对数据帧中的列进行排序(ordering columns in dataframe based on incomplete vector)

我有一个基于col名称的矢量,看起来像

x <- c("C", "A", "T")

我的数据框看起来像是定义了rownames和colnames。

names    A    B    C    D    T
 Dan     1    0    1    0    1
 Joe     0    1    0    1    0

我想对数据帧进行排序,以便首先显示向量中的列,然后是不在向量中的列

names    C    A    T   B    D
Dan      1    1    1   0    0
Joe      0    0    0   1    1

谢谢


I have a vector based on col names which looks like

x <- c("C", "A", "T")

my dataframe looks like with rownames and colnames defined.

names    A    B    C    D    T
 Dan     1    0    1    0    1
 Joe     0    1    0    1    0

I want to order the dataframe so the columns in the vector appear first followed by columns not in the vector

names    C    A    T   B    D
Dan      1    1    1   0    0
Joe      0    0    0   1    1

Thanks


原文:https://stackoverflow.com/questions/45436626
更新时间:2023-09-17 22:09

最满意答案

能够使用jQuery 1.12.4和UI 1.12.1复制问题,匹配Demo版本: http//jqueryui.com/datepicker/ 。 工作测试: https//jsfiddle.net/Twisty/wkpvbp5u/

如果我注释掉showCurrentAtPos ,它会按预期工作。

JavaScript的

$(function() {
  $('#date').datepicker({
    numberOfMonths: 4,
    //showCurrentAtPos: 1,
    showButtonPanel: true
  });
});

所以问题可能出在这个选项的行为上。 我通过将值设置为-1作为测试来打破它。 “下一步”按钮失败。

发现: https//bugs.jqueryui.com/ticket/15129所以看起来你可以使用jQuery UI 1.11.4而不是1.12.1。 可能是一个修复: https//github.com/jquery/jquery-ui/commit/17404ced478a235651513fa7bef3473ef1b039e8

希望有所帮助。


Was able to replicate the issue using jQuery 1.12.4 & UI 1.12.1, matching Demo versions: http://jqueryui.com/datepicker/. Working test: https://jsfiddle.net/Twisty/wkpvbp5u/

If I comment out showCurrentAtPos, it works as expected.

JavaScript

$(function() {
  $('#date').datepicker({
    numberOfMonths: 4,
    //showCurrentAtPos: 1,
    showButtonPanel: true
  });
});

So the issue may be in behavior of this option. I broke it more by setting the value to -1 as a test too. The Next button fails.

Found: https://bugs.jqueryui.com/ticket/15129 so looks like you can use jQuery UI 1.11.4 but not 1.12.1. Might be a fix: https://github.com/jquery/jquery-ui/commit/17404ced478a235651513fa7bef3473ef1b039e8

Hope that helps.

相关问答

更多
  • 问题在于缺少功能: onChangeMonthYear: function () { setTimeout(function() { updateRefs(); }, 0); } 整码: