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

dcast.data.table loses column attributes #688

Closed
juancentro opened this issue Jun 9, 2014 · 0 comments
Closed

dcast.data.table loses column attributes #688

juancentro opened this issue Jun 9, 2014 · 0 comments
Assignees
Labels
Milestone

Comments

@juancentro
Copy link

When casting a data.table, a date column loses its attributes

require(data.table)
data = data.table(id = c(1,1,2,2), ty = c("a","b","a","b"), da = Sys.Date())
dcast.data.table(data, formula = id ~ ty) 
# Using 'da' as value column. Use 'value.var' to override
#    id     a     b
#1:  1 16230 16230
#2:  2 16230 16230

Quoting @arunsrinivasan

This is because reshape2:::dcast doesn't preserve attributes. And we wanted to be consistent with their result at the time of writing.
However, since that time, reshape2 has obtained newer implementation of "melt", written by Kevin Ushey, where attributes are preserved as long as all the columns that you're asking for to be "molten" are of the same type. But this doesn't happen for "factors" by default because that might break existing code - and therefore obtained a new argument "factorsAsStrings", IIUC. I personally find these things adding a layer of complexity. But that's the case with "melt".

It's really hard to tell from reshape2's ?melt or ?cast what's the case regarding attributes. But my guess is that we should, starting with your post, try to define what's what and document it instead of relying entirely on being consistent with reshape2's behaviour, as we do already differ from reshape2 already slightly.

We're very much younger than reshape2's melt/cast. So, I think we might be able to rectify these things on consistency and rules relatively easier.

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

No branches or pull requests

2 participants