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
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: 11623016230
#2: 21623016230
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.
The text was updated successfully, but these errors were encountered:
When casting a
data.table
, a date column loses its attributesQuoting @arunsrinivasan
The text was updated successfully, but these errors were encountered: