Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data.table(x) != as.data.table(x) #877

Closed
jamesonquinn opened this issue Oct 11, 2014 · 4 comments
Closed

data.table(x) != as.data.table(x) #877

jamesonquinn opened this issue Oct 11, 2014 · 4 comments
Assignees
Milestone

Comments

@jamesonquinn
Copy link

Here's the motivating example which had me mightily confused at first:

l = list(x=1,y=2)
data.frame(l)
#   x y
#1 1 2
as.data.table(l)
#    x y
#1: 1 2
data.table(l)
#    l
#1: 1
#2: 2

Now that I've explored this issue, I understand what's going on. But at the very least, there should be an entry in the faq about this.

The issue is that you might say data.table(listOne,listTwo) (or indeed, data.table(vectorOne,vectorTwo)) to create a two-column table, while as.data.table should only take one argument. Personally, I think the default here is wrong; it would make more sense, and be easier to troubleshoot bugs, if data.table(listOne) was the same as as.data.table(listOne), rather than being similar to data.table(listOne, listTwo).

This is touched on in the FAQ when it says "data.frame(list(1:2,"k",1:4)) creates 3 columns, data.table creates one list column." Still, I think that ideally the default should change: data.table with one argument should be the same as as.data.table. If not, this behavior should at least be better-documented.

@jangorecki
Copy link
Member

@jamesonquinn please check related issue: #968 (comment)
Do you have an idea how would be possible in such case to create a data.table with one list column? If you don't have an idea for this then I believe this issue can be closed as it has to be possible to create one list column data.table.

@arunsrinivasan
Copy link
Member

I've noted this in #944 to expand on this point under FAQ. The underlying idea is to facilitate creation of list columns in a straightforward manner. If you've a list and would like to create a data.table then use as.data.table(); it's more appropriate.

@arunsrinivasan
Copy link
Member

@jamesonquinn, Do you've any thoughts on how better to document it? Currently, the difference is stated clearly under "differences between data.frame and data.table. I can't think of a more appropriate section. I'm guessing you want to expand on the content?

@eantonya
Copy link
Contributor

eantonya commented Feb 8, 2015

Just for reference, list behaves similarly in base R. as.list(c(1:5)) and list(c(1:5)) yield very different results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants