【发布时间】:2018-06-15 16:49:36
【问题描述】:
我有一个看起来像这样的data.table,
dt <- data.table(
cbind(
id = c( 1, 1, 2, 2, 3, 3, 3 ),
y = c( 'a', 'b', 'c', 'd', 'e', 'f', 'g' )
)
);
我想将其转换为如下所示的data.table:
id y.list
1: 1 list( a, b )
2: 2 list( c, d )
3: 3 list( e, f, g )
上面的list 可以是任何容器,即vector、简单的c,或者可以在以后迭代的任何其他容器。感谢您的任何建议!
【问题讨论】:
-
你不需要
cbind...你可以直接去dt <- data.table(id = ...)
标签: r data.table