我想按递减顺序排列日期。
目前我正在使用这种方法,但它并不总是有效。
data.frame(zoo(data order.by=as.POSIXct(data$date)), row.names=NULL)
列date
包含以下值:
x <- "2261 2017-04-14 08:42:17.287374
2262 2017-04-14 08:44:30.683207
2263 2017-04-14 08:46:43.611042
2264 2017-04-14 08:48:56.991276
2265 2017-04-14 11:24:26.808124
2266 2017-04-14 08:51:09.794308
2267 2017-04-14 08:54:06.324218
2268 2017-04-14 08:56:19.610852"
d <- read.table(text=x, header=F)
请注意,V1
是data.frame中的rownames
而V2
和V3
并未分开,只有一列名为date
所以这比我更接近:
data <- data.frame(date=paste(d$V1,d$V2, sep=" "))
答案 0 :(得分:2)
x <- "2261 2017-04-14 08:42:17.287374
2262 2017-04-14 08:44:30.683207
2263 2017-04-14 08:46:43.611042
2264 2017-04-14 08:48:56.991276
2265 2017-04-14 11:24:26.808124
2266 2017-04-14 08:51:09.794308
2267 2017-04-14 08:54:06.324218
2268 2017-04-14 08:56:19.610852"
d <- read.table(text=x, header=F)
rnames = d$V1
d$Date = paste(d$V2, d$V3)
d$Date = as.POSIXct(d$Date)
rownames(d) = rnames
d = d[order(d$Date, decreasing = TRUE), ]
d = d["Date"]
> d
Date
2265 2017-04-14 11:24:26
2268 2017-04-14 08:56:19
2267 2017-04-14 08:54:06
2266 2017-04-14 08:51:09
2264 2017-04-14 08:48:56
2263 2017-04-14 08:46:43
2262 2017-04-14 08:44:30
2261 2017-04-14 08:42:17