[英]Subsetting columns works on data.frame but not on data.table
我可以從data.frame
選擇幾列:
> z[c("events","users")]
events users
1 26246016 201816
2 942767 158793
3 29211295 137205
4 30797086 124314
但不是來自data.table
:
> best[c("events","users")]
Starting binary search ...Error in `[.data.table`(best, c("events", "users")) :
typeof x.pixel_id (integer) != typeof i.V1 (character)
Calls: [ -> [.data.table
我該怎么辦? 有沒有更好的辦法,而不是轉data.table
回一個data.frame
?
鑒於您正在尋找data.table
您應該在調用的j
部分使用list
而不是c
。
z[, list(events,users)] # first comma is important
請注意,您不需要列名周圍的引號。
列子集應該在j
完成,而不是在i
。 改為:
DT[, c("x", "y")]
查看此演示文稿(幻燈片 4)以了解如何讀取data.table
語法(更像 SQL)。 這將有助於說服您在j
提供列更有意義 - 相當於 SQL 中的 SELECT。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.