I have a question regarding the use of the function order (), I have the following data.frame and I am using the following statement but I can not sort the column, and can not find the error. I want this column Tag_PHASE ordered from lowest to highest.
我有一个关于函数order()的使用的问题,我有以下data.frame并且我使用以下语句但我无法对列进行排序,并且无法找到错误。我希望此列Tag_PHASE从最低到最高排序。
Tag_PHASE Num_EPC
1 101.0 1
2 126.0 1
3 70.0 1
4 73.0 1
5 78.0 3
6 81.0 1
7 84.0 1
8 87.0 1
9 90.0 1
10 92.0 3
a<-DF_TAG_PHASE_EPC_counter[order(DF_TAG_PHASE_EPC_counter$Tag_PHASE), ]
1 个解决方案
#1
1
Here is an attempt:
这是一个尝试:
DF_TAG_PHASE_EPC_counter <-
data.frame(Tag_PHASE = runif(10)*100, Num_EPC = sample(c(1,3), 10,prob = c(.7,.3), replace = T))
DF_TAG_PHASE_EPC_counter
DF_TAG_PHASE_EPC_counter[order(DF_TAG_PHASE_EPC_counter$Tag_PHASE),]
Note: You are assigning the results to a:
注意:您将结果分配给:
a <- DF_TAG_PHASE_EPC_counter[order(DF_TAG_PHASE_EPC_counter$Tag_PHASE),]
So to see the results you'll have to print a
所以要查看结果,你必须打印一个
a
Here is a simpler way to do this:
这是一种更简单的方法:
library(data.table)
DT <- setDT(DF_TAG_PHASE_EPC_counter)
DT[order(Tag_PHASE)]
Read more here
在这里阅读更多
#1
1
Here is an attempt:
这是一个尝试:
DF_TAG_PHASE_EPC_counter <-
data.frame(Tag_PHASE = runif(10)*100, Num_EPC = sample(c(1,3), 10,prob = c(.7,.3), replace = T))
DF_TAG_PHASE_EPC_counter
DF_TAG_PHASE_EPC_counter[order(DF_TAG_PHASE_EPC_counter$Tag_PHASE),]
Note: You are assigning the results to a:
注意:您将结果分配给:
a <- DF_TAG_PHASE_EPC_counter[order(DF_TAG_PHASE_EPC_counter$Tag_PHASE),]
So to see the results you'll have to print a
所以要查看结果,你必须打印一个
a
Here is a simpler way to do this:
这是一种更简单的方法:
library(data.table)
DT <- setDT(DF_TAG_PHASE_EPC_counter)
DT[order(Tag_PHASE)]
Read more here
在这里阅读更多