0

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.

    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), ]
Thomas
  • 43,637
  • 12
  • 109
  • 140
Alex
  • 151
  • 13

1 Answers1

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

Community
  • 1
  • 1
Shambho
  • 3,250
  • 1
  • 24
  • 37