Repository navigation
Creation of data.table using a list #968
Description
Activity
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..
It's worth noting that
as.data.tablebehaves as expected; it is onlydata.tablethat 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,eTested with today's devel version of data.table.
data.tablebehave differently thandata.framebut still behave as expected.
What you do bydata.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?structure(list(l = list(1:5, c(0.182844649428989, 0.858360447353789, -0.0532774982161298, 0.459157422043729, 0.822852400527859), c("a", "b", "c", "d", "e"))), .Names = "l", row.names = c(NA, -3L), class = c("data.table", "data.frame"))
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 [email protected]
wrote: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?structure(list(l = list(1:5, c(0.182844649428989, 0.858360447353789, -0.0532774982161298, 0.459157422043729, 0.822852400527859), c("a", "b", "c", "d", "e"))), .Names = "l", row.names = c(NA, -3L), class = c("data.table", "data.frame"))
—
Reply to this email directly or view it on GitHub
#968 (comment)
.@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 :)
This is a very similar issue as what is mentioned here: http://stackoverflow.com/questions/18390947/data-table-of-table-is-very-different-from-data-frame-of-table
yet this pertains to creating data.tables using a list input. For example:
I discovered this behavior at least a year ago when I was trying to create a data.table object using mget
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.