0
저는 열과 행의 개인이있는 십자가 테이블 (table
으로 작성)을 가지고 있습니다. 수평 공간을 절약하기 위해 4 자리 연도가 아닌 2 자리 연도를 사용하고 싶습니다 (다운 스트림은 xtable
을 통해 LaTeX로갑니다). 그러나 주문한 요소 (ordered()
또는 factor(..., ordered=TRUE)
)를 사용하면 연대순으로 정렬하는 것이 아니라 숫자순으로 정렬됩니다.십자가 도표에서 연대순으로 두 자리 연도를 주문하십시오.
시간순으로 열 순서를 지정할 수 있습니까? 주문한 요소를 table
에 전달하면 주문 속성이 없어집니다.
# representative data
dates <- as.Date("2010-01-01") - seq(30*365)
DF <- data.frame(day=sample(dates, 100, replace=TRUE),
id=sample(letters[1:5], 100, replace=TRUE))
DF$year <- as.numeric(format(DF$day, "%Y"))
# the table I want
table(DF$id, DF$year)
# but I'd like two year dates to save horizontal space
# but keep chronological order
DF <- DF[order(DF$day), ]
DF$yearShort <- factor(format(DF$day, "%y"), ordered=TRUE)
# but even though yearShort is ordered, the table isn't
is.ordered(DF$yearShort)
tab <- table(DF$id, DF$yearShort)
tab
# I can't order by rownames, either
tab[, order(dimnames(tab)[[2]])]
샤프을 원하는 않습니다. 이것은 유일한 해결책 일 수 있습니다. –