[datatable-help] Discrepancy between as.data.frame & as.data.table when handling nested lists

Ricardo Saporta saporta at scarletmail.rutgers.edu
Wed Aug 7 23:56:02 CEST 2013


Hi all,

Note the following discrepancy in structure between as.data.frame &
as.data.table when called on a nested list.
as.data.frame converts the sublist into individual columns whereas
as.data.table stacks them into a single column and creates additional rows.

Is this intentional?
-Rick


as.data.frame(X)
#        start       type      end data.editDist data.second
# 1 start_node is_similar end_node             1  HelloWorld

as.data.table(X)
#         start       type      end       data
# 1: start_node is_similar end_node          1
# 2: start_node is_similar end_node HelloWorld




### Copy+Paste'able Below ###

# Example 1:
X <-  structure(list(start = "start_node", type = "is_similar", end =
"end_node",
    data = structure(list(editDist = 1, second = "HelloWorld"), .Names =
c("editDist",
    "second"))), .Names = c("start", "type", "end", "data"))

as.data.frame(X)
as.data.table(X)

as.data.table(as.data.frame(X))


# Example 2, with more elements:
Y <- structure(list(start = c("start_node", "start_node"), type =
c("is_similar", "is_similar"), end = c("end_node", "end_node"), data =
structure(list(editDist = c(1, 1), second = c("HelloWorld", "HelloWorld")),
.Names = c("editDist", "second"))), .Names = c("start", "type", "end",
"data"))

as.data.frame(Y)
as.data.table(Y)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130807/6bd6e199/attachment.html>


More information about the datatable-help mailing list