1

I am struggling to order column in my dataset. The way I want to reorder can be shown in the following example:

I have the following data:

dd = data.frame("AssignedA"=1:2, "AverageA"=1, "AssignedB"=1, "AverageB"=1,
  "AssignedC"=1, "AverageC"=1, "ValueA"=1, "ValueB"=1, "ValueC"=1)

For an easy overview, I would like the columns to be ordered in the following way:

Assigned A - Assigned B - Assigned C - Average A - Average B - Average C- Value A - Value B - Value C

How to do this? I couldn't find the solution in questions posted earlier.

4

1 に答える 1

2

シンプルに保ちseq、列の順序を作成するために使用します。まず、(質問でこれを行う必要があります)、ダミーデータを作成します。

dd = data.frame("AssignedA"=1:2, "AverageA"=1, "AssignedB"=1, "AverageB"=1,
  "AssignedC"=1, "AverageC"=1, "ValueA"=1, "ValueB"=1, "ValueC"=1)

次に、通常どおり並べ替えます。

dd[,c(seq(1,6,2), seq(2,6,2), 7:9)]

ここで、 のコマンド[]は順序を指定します。

R> c(seq(1,6,2), seq(2,6,2), 7:9)
[1] 1 3 5 2 4 6 7 8 9
于 2012-04-18T08:48:21.827 に答える