r - Access a single cell / subsetted column of a data.table -


how can access single cell in data.table in way data.frame:

mdf <- data.frame(a = c("a", "b", "c"), b = rnorm(3), c = 1:3) mdf[ mdf$a == "b", "c" ] [1] 2 

doing analogue on data.table data.table returned including key column(s):

mdt <- data.table( mdf, key = "a" ) mdt[ "b", c ]    c 1: b 2  mdt[ "b", c ][ , c] [1] 2 

did miss parameter or has done in last line?

either of these avoid repeating c not efficient since involve computing first [] final answer:

> mdt[ "b", ][["c"]] [1] 2 > mdt[ "b", ][, c] [1] 2 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -