How to read "paired data" into an R data.table? Using an R list? -
let's have data.table
in r:
library("data.table") dt = data.table(x=c("b","b","b","a","a","a"),v=rnorm(6)) > dt x v 1: b 0.77399102 2: b 0.71450334 3: b 0.07187842 4: -0.88098815 5: -0.90192891 6: 0.66439642
i supply vector x
field, , vector v
field, each 6 items.
however, see supply b
3 times, , a
3 times. key-value pair, i.e.
'b' : '0.77399102', '0.71450334', '0.07187842' 'a' : '-0.88098815', '-0.90192891', '0.66439642'
in r, 1 implement list, i.e.
pairs = list(b = c('0.77399102', '0.71450334', '0.07187842'), = c('-0.88098815', '-0.90192891', '0.66439642'))
i input r list pairs
data.table
. possible? i'm confused how define x
, v
fields object. if isn't possible, how 1 this?
use data.table(x = names(pairs), v = pairs)
. works data.frame
.
Comments
Post a Comment