In data.table可能有类型的列,list我第一次尝试从此功能中受益.我需要为我的表的每一行存储dt从rApache Web服务获取的几条注释.每条评论都有一个用户名,日期时间和正文项.
而不是使用带有一些奇怪的,不寻常的字符的长字符串来将每个消息与其他消息分开(例如|),并且;要分隔评论中的每个项目,我想使用这样的列表:
library(data.table)
dt <- data.table(id=1:2,
comment=list(list(
list(username="michele", date=Sys.time(), message="hello"),
list(username="michele", date=Sys.time(), message="world")),
list(
list(username="michele", date=Sys.time(), message="hello"),
list(username="michele", date=Sys.time(), message="world"))))
> dt
id comment
1: 1 <list>
2: 2 <list>
Run Code Online (Sandbox Code Playgroud)
存储为一个特定行添加的所有注释.(也因为JSON当我需要将其发送回用户界面时,将更容易转换为以后)
但是,当我尝试模拟在生产过程中我将如何填充表格时(向特定行添加单个注释),R要么崩溃,要么不分配我想要的然后崩溃:
library(data.table)
> library(data.table)
> dt <- data.table(id=1:2, comment=vector(mode="list", length=2))
> dt$comment
[[1]]
NULL
[[2]]
NULL
> dt[1L, comment := 1] # this works
> dt$comment
[[1]]
[1] 1
[[2]]
NULL
> set(dt, 1L, …Run Code Online (Sandbox Code Playgroud)