5

Rパッケージdata.tableに関する質問:メモリ効率の高い方法で複数のdata.table列を削除するにはどうすればよいですか?

削除する列名がベクトルdeleteColに格納されているとします。

In a data.frame, it is:
DF <- DF[deleteCol] <- list()

data.tableについては、次のことを試しました。

DT[, deleteCol, with=FALSE] <- list()

しかし、これは与えましたunused argument(s) (with = FALSE)

4

1 に答える 1

5

ここにいくつかのオプションがあります。最後のものはまさにあなたが望むもののようです...

 x<-1:5
 y<-1:5
 z<-1:5
 xy<-data.table(x,y,z)
 NEWxy<-subset(xy, select = -c(x,y) ) #removes column x and y

id<-c("x","y")
newxy<-xy[, id, with=FALSE]
newxy #gives just x and y e.g.

   #  x y
#[1,] 1 1
#[2,] 2 2
#[3,] 3 3
#[4,] 4 4
#[5,] 5 5

そして最後にあなたが本当に欲しいもの:

anotherxy<-xy[,id:=NULL,with=FALSE] # removes comuns x and y that are in id

#     z
#[1,] 1
#[2,] 2
#[3,] 3
#[4,] 4
#[5,] 5
于 2012-05-14T10:08:01.717 に答える