我試圖將子集從data.frame轉換爲data.table
以改善我的代碼的性能。但我對data.table
完全陌生。 data.table
此子集表述類型的等效項目是什麼?將聯合類型子集從data.frame轉換爲data.table
for(ii in 1:nplayer)
{
subgame<-subset(game, game$playerA == player[ii] | game$playerB == player[ii])
players[ii,4]<-nrow(subgame)
}
我已經定義了這樣一個新的data.table
gameDT
dput的
gameDT<-data.table(game)
setkey(gameDT,playerA,playerB)
輸出
>dput(game[1:2,])
structure(list(country = c("New Zealand", "Australia"), tournament = c("WTA Auckland 2012",
"WTA Brisbane 2012"), date = c("2011-12-31 00:00:00", "2011-12-30 00:15:00"
), playerA = c("Schoofs B.", "Lucic M."), playerB = c("Puig M.",
"Tsurenko L."), resultA = c(1L, 1L), resultB = c(2L, 2L), oddA = c("1.8",
"2.17"), oddB = c("1.9", "1.57"), N = c(4L, 3L), Weight = c(1,
0.973608997871031)), .Names = c("country", "tournament", "date",
"playerA", "playerB", "resultA", "resultB", "oddA", "oddB", "N",
"Weight"), row.names = 1:2, class = "data.frame")
你能dput數據集或它的子集(例如dput(遊戲[1:20,]))? –
'data.table'中的子集語法就是'dt [playerA ==「a」| playerB ==「a」]' –