I am a little surprised at how data.table works:
> library(data.table) data.table 1.8.2 For help type: help("data.table") > dt <- data.table(a=11:20, b=21:30, c=31:40, key="a") > dt[list(12)] abc 1: 12 22 32 > dt[list(12), b] ab 1: 12 22 > dt[list(12)][,b] [1] 22
What I'm trying to do is get the value of one column (or expression) in the rows corresponding to the selected one. I see that I need to pass the key as a list, since the raw number will indicate the line number, not the key value. So, the first of the above is clear to me. But why the second and next expression of the subset give different results seems to me rather confusing. I would like to get the third result, but you could write it in the second way.
Is there a good reason why a subset of data.table for rows and columns at the same time will always include the key value as well as the calculated result? Is there a syntactically shorter way to get a single result, with the exception of a double subset, as mentioned above?
I am using data.table 1.8.2 on R 2.15.1. If you cannot reproduce my example, you can also consider the factor as a key:
dt <- data.table(a=paste("a", 11:20, sep=""), b=21:30, c=31:40, key="a") dt["a11", b]
source share