2
我有六只鹦鹉鸟,"Beefy", "Scoundrel", "Baston", "Mattdamon", "Jesus", and "Hulkhogan"
。这些鸟在很多不同的地方都会呕吐。我已经决定追踪过去两周内这种情况发生的频率,我试图弄清楚今天这些小恶魔在哪里发生的事情。按行中的行数值排列数据,并按列中的值排序R
mydata <- data.frame(Dates = structure(c(16656, 16657, 16658, 16659,
16660, 16661, 16662, 16663,
16664, 16665, 16666, 16667,
16668, 16669
),
class = "Date"),
PooLoc1 = sample(1:40, 7),
PooLoc2 = sample(1:10, 7),
PooLoc3 = sample(1:10, 7),
PooLoc4 = sample(1:30, 7),
PooLoc5 = sample(1:20, 7),
PooLoc6 = sample(1:70, 7)
)
head(mydata)
Dates PooLoc1 PooLoc2 PooLoc3 PooLoc4 PooLoc5 PooLoc6
2015-08-09 24 3 9 1 16 45
2015-08-10 39 2 2 12 12 2
2015-08-11 14 7 6 5 19 4
2015-08-12 26 9 8 27 3 64
2015-08-13 20 4 1 15 20 48
2015-08-14 9 1 4 8 8 61
我可以为了mydata
行柱日期很容易地找到今天的普斯像这样:
mydata <- mydata[order(mydata[["Dates"]], decreasing = TRUE), ]
但我怎么通过今天的日期获得这样我就可以立马值排序列在mydata
的左上角找到我的问题的答案?你能做到一行吗?
由于订购一个呼叫的行和列!是否可以在一行中进行列排序和日期排序? – r3robertson
是的,只要把你的日期顺序调用放在逗号左边,列顺序在右边,像这样 - 'mydata [order(mydata $ Dates,decrease = TRUE),c(1,order(mydata [1 ,-1],递减= TRUE)+ 1)]' –