You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
yet this pertains to creating data.tables using a list input. For example:
### Data.frame takes in a list of 3 3x3 matrices, and creates a 3x9 data.frame.
data.frame(replicate(3, matrix(rnorm(9), nrow = 3)))
### Data.table takes in the same list, and creates a 27x1 data.table.
data.table(replicate(3, matrix(rnorm(9), nrow = 3)))
I discovered this behavior at least a year ago when I was trying to create a data.table object using mget
a <- letters
b <- LETTERS
vars <- c("a", "b")
### Works
data.frame(mget(vars))
### Doesn't work
data.table(mget(vars))
There are probably really good reasons for having this behavior that I am not aware of as a user, but at the same time it would be great to have data.table behaving as similarly as possible to data.frame!
Thanks for such a great package! I haven't used data.frame in years, and couldn't be happier.
It's worth noting that as.data.table behaves as expected; it is only data.table that behaves differently.
l <- list(x = 1:5, y = rnorm(5), z = letters[1:5])
as.data.frame(l)
## x y z
## 1 1 -0.09738263 a
## 2 2 1.47511422 b
## 3 3 0.22953616 c
## 4 4 0.08974962 d
## 5 5 1.21911408 e
data.frame(l)
## x y z
## 1 1 -0.09738263 a
## 2 2 1.47511422 b
## 3 3 0.22953616 c
## 4 4 0.08974962 d
## 5 5 1.21911408 e
as.data.table(l)
## x y z
## 1: 1 -0.09738263 a
## 2: 2 1.47511422 b
## 3: 3 0.22953616 c
## 4: 4 0.08974962 d
## 5: 5 1.21911408 e
data.table(l)
## l
## 1: 1,2,3,4,5
## 2: -0.09738263, 1.47511422, 0.22953616, 0.08974962, 1.21911408
## 3: a,b,c,d,e
data.table behave differently than data.frame but still behave as expected.
What you do by data.table(l) is creating 1 column data.table which contains a list type column.
How would you create below data.table if it wouldn't behave as it is now?
data.table behave differently than data.frame but still behave as
expected.
What you do by datat.table(l) is creating 1 column data.table which
contains a list column.
How would would create below data.table if it wouldn't behave as it is now?
@asantucci just don't forget to close this issue (assuming it is resolved) when you will have access to github (I see you did reply via email).
PS. data.table is also my favorite part of R :)
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.
Activity
arunsrinivasan commentedon Dec 4, 2014
Thanks. Could you please read completely and follow the instructions here?
Add the output you get wherever possible, comment the output, tell us which version you're using etc..
richierocks commentedon Dec 10, 2014
It's worth noting that
as.data.tablebehaves as expected; it is onlydata.tablethat behaves differently.Tested with today's devel version of data.table.
jangorecki commentedon Dec 10, 2014
data.tablebehave differently thandata.framebut still behave as expected.What you do by
data.table(l)is creating 1 column data.table which contains alisttype column.How would you create below data.table if it wouldn't behave as it is now?
asantucci commentedon Dec 10, 2014
as.data.table is what I was looking for.
Thank you so much for all the follow up. I agree that the behavior is as
expected for both data.table and as.data.table.
Thank you for maintaining such an excellent package! It's really my
favorite part of R.
On Wed, Dec 10, 2014 at 1:46 PM, Jan Gorecki notifications@github.com
wrote:
jangorecki commentedon Dec 10, 2014
@asantucci just don't forget to close this issue (assuming it is resolved) when you will have access to github (I see you did reply via email).
PS. data.table is also my favorite part of R :)
arunsrinivasan commentedon Feb 8, 2015
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.Also closing #877.