我试图将子集从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”]' –