我在 R 中订购表时遇到问题。 我有这张表:
Date Race time Fav Odds win place joint
01/04/2013 Redcar 14:30 4 1 n y j
01/04/2013 Redcar 15:00 9 4 n y
01/04/2013 Redcar 15:30 7 4 n y
01/04/2013 Redcar 16:00 11 4 y j
01/04/2013 Redcar 16:30 9 4 n y
01/04/2013 Redcar 17:00 7 2 n n
01/04/2013 Redcar 17:30 6 4 n n
01/04/2013 Warwick 14:20 8 13 y
01/04/2013 Warwick 14:50 9 2 y j
01/04/2013 Warwick 15:20 6 4 y
01/04/2013 Warwick 15:50 7 4 n n
01/04/2013 Warwick 16:20 7 4 n n
01/04/2013 Warwick 16:50 11 8 n n
01/04/2013 Yarmouth 14:05 10 11 n n
01/04/2013 Yarmouth 14:40 5 2 y j
01/04/2013 Yarmouth 15:10 10 3 n n
01/04/2013 Yarmouth 15:40 7 2 n n
01/04/2013 Yarmouth 16:10 2 1 n n
01/04/2013 Yarmouth 16:40 11 10 n y
01/04/2013 Yarmouth 17:10 7 2 n n
02/04/2013 Kempton 14:00 7 2 y
02/04/2013 Kempton 14:30 13 8 n y
02/04/2013 Kempton 15:00 7 4 n y
02/04/2013 Kempton 15:30 10 11 y
02/04/2013 Kempton 16:00 2 1 n y
02/04/2013 Kempton 16:30 4 1 n n
02/04/2013 Kempton 17:00 11 4 n y
02/04/2013 Southwell 14:20 1 2 y
02/04/2013 Southwell 14:50 11 8 y
02/04/2013 Southwell 15:20 2 1 n y
02/04/2013 Southwell 15:50 7 2 n y j
02/04/2013 Southwell 16:20 8 13 y
02/04/2013 Southwell 16:50 9 4 n
02/04/2013 Southwell 17:20 13 8 n n
03/04/2013 Dundalk 18:20 7 2 y
03/04/2013 Dundalk 18:50 11 8 n n
03/04/2013 Dundalk 19:20 3 1 n y
03/04/2013 Dundalk 19:50 11 4 n n
03/04/2013 Dundalk 20:20 6 4 n y
03/04/2013 Dundalk 20:50 1 5 n y
03/04/2013 Dundalk 21:20 13 8 n y
03/04/2013 Kempton 17:30 11 8 n n
03/04/2013 Kempton 18:00 7 4 y j
03/04/2013 Kempton 18:30 8 11 n y
03/04/2013 Kempton 19:00 1 2 n y
03/04/2013 Kempton 19:30 5 2 n y
03/04/2013 Kempton 20:00 2 1 y
03/04/2013 Kempton 20:30 4 5 n y
03/04/2013 Lingfield 14:00 4 5 n n
03/04/2013 Lingfield 14:30 4 7 y
03/04/2013 Lingfield 15:00 6 4 y
03/04/2013 Lingfield 15:30 3 1 n y
03/04/2013 Lingfield 16:00 2 1 n y
03/04/2013 Lingfield 16:30 4 6 n n
03/04/2013 Lingfield 17:00 6 4 y
03/04/2013 Southwell 14:20 6 4 y
03/04/2013 Southwell 14:50 7 4 n n
03/04/2013 Southwell 15:20 1 4 y
03/04/2013 Southwell 15:50 10 11 n n
03/04/2013 Southwell 16:20 4 7 n n
03/04/2013 Southwell 16:50 13 8 y
03/04/2013 Southwell 17:20 5 2 y
04/04/2013 Lingfield 14:20 11 4 y
04/04/2013 Lingfield 14:55 4 6 y
04/04/2013 Lingfield 15:30 9 4 y
04/04/2013 Lingfield 16:05 11 4 n y
04/04/2013 Lingfield 16:40 6 4 n y
04/04/2013 Lingfield 17:15 7 4 y
04/04/2013 Lingfield 17:45 6 4 n n
我需要按升序在 R 内按升序排序,并分别对其他列进行排序。我尝试首先将其分配给名为table
的变量:
table <- read.csv("assessment.csv")
之后,当我尝试将该表存储到名为sortedTable
的新表中时:
sortedTable <- table[order(time),]
我收到此错误:
顺序错误(时间):参数1不是向量
我设法做了一次,我不知道怎么做,但即便如此,桌子已经排序但是在某个地方,连续14:00,这很奇怪。如何正确对表格进行排序?
答案 0 :(得分:0)
从左到右要order
data.frame的列,请使用do.call
。例如:
mtcars[do.call("order",mtcars),]
mpg cyl disp hp drat wt qsec vs am gear carb
Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4
Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8
...
答案 1 :(得分:0)
如果table
很大(很多行),使用数据表可能会更快:
library(data.table)
dt <- data.table(table)
sorted <- setkeyv(dt,colnames(dt))