3
下面是示出該問題的可再現例如:從數據幀變換爲數據表獲得帶有頭部(..)的誤差
openSummary <- read.table(textConnection(
"Dates dollarA numTotal
7/3/2011 52730.56 1614
7/10/2011 77709.43 1548"), header = TRUE)
openSummary$Dates <- strptime(openSummary$Dates,"%m/%d/%Y")
str(openSummary)
head(openSummary) # No problem
openSummaryDT <- data.table(openSummary)
str(openSummaryDT)
head(openSummaryDT) # An error is produced
以下是錯誤在執行頭(openSummaryDT)
Error in `rownames<-`(`*tmp*`, value = paste(format(rn, right = TRUE), :
length of 'dimnames' [1] not equal to array extent
請解釋錯誤,我該如何避免它。但是,似乎我可以在數據框和數據表上執行一些操作,並獲得相同的結果。
difftime(Sys.Date(), openSummary[ ,"Dates"])
difftime(Sys.Date(), openSummaryDT[ ,Dates])
預先感謝您
目前POSIXlt列不受'data.table'支持(請參閱[這裏](http://stackoverflow.com/a/14063077/1385941))。 – mnel
@mnel它似乎應該錯誤,然後,不是?感謝您的鏈接,我沒有意識到(儘管我從來沒有需要使用'POSIXlt'。 – BrodieG