Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 重新排列具有相同值的数据行_R_Sorting - Fatal编程技术网

R 重新排列具有相同值的数据行

R 重新排列具有相同值的数据行,r,sorting,R,Sorting,我有以下数据: Data <- data.frame(Project=c(123,123,123,123,123,123,124,124,124,124,124,124), Date=c("12/27/2016 15:16","12/27/2016 15:20","12/27/2016 15:24","12/27/2016 15:28","12/27/2016 15:28","12/27/2016 15:42","12/28/2016 7:22","12/28

我有以下数据:

Data <- data.frame(Project=c(123,123,123,123,123,123,124,124,124,124,124,124),
               Date=c("12/27/2016 15:16","12/27/2016 15:20","12/27/2016 15:24","12/27/2016 15:28","12/27/2016 15:28","12/27/2016 15:42","12/28/2016 7:22","12/28/2016 7:26","12/28/2016 7:35","12/28/2016 11:02","12/28/2016 11:02","12/28/2016 11:28"),
               OldValue=c("","Open","In Progress","Open","System Declined","In Progress","System Declined","Open","In Progress","Open","Complete","In Progress"),
               NewValue=c("Open","In Progress","System Declined","In Progress","Open","System Declined","Open","In Progress","Complete","In Progress","Open","Complete"))

如果将
OldValue
作为一个因素,则按字母顺序排列数据将产生不同的结果。我已尝试按项目、日期、OldValue以及大多数有效的部分对数据进行排序。但是,在上面的例子中,如果
OldValue
是一个因素,则第4行、第5行按字母顺序排序将产生不同的结果。我尝试过按项目、日期、OldValue和大多数有效的部分对数据进行排序。但是,在上面的例子中,也有这样的情况,即第4行、第5行不起作用
#Assign Desired order to the OldValue, CHANGE "y" IF NECESSARY
OldValue_order = data.frame(OldValue = c("","Open","In Progress","System Declined","Complete"), y = c(0,4,2,1,3))

# We'll need lookup command to copy desired order to the "Data"
library(qdapTools)
Data$OV_order = lookup(Data$OldValue, OldValue_order) # Adds new column to "Data"

# Arrange the data.frame in desired order
Data = Data[with(Data, order(Project, as.POSIXct(Date, format = "%m/%d/%Y %H:%M"), OV_order)),]

#Remove the added column
Data = Data[1:4]