juliasilge/widyr

Feature request: retaining factor metadata

noamross opened this issue · 1 comments

A pattern I've run into a few times is that I have a data frame with factor column that I widen in order to perform some operation, and the factors become column headers, then I tidy again, and in the new incarnation of the data frame the column is a character column instead, and I may have lost my factor ordering.

I see this happens in the very first example in your README.

It would be great if widyr could retain the factor information in a widen-operate-tidy operation. I would suggest having this be the default behavior.

CC @mdsumner

You're right. In fact this should probably extend further: whatever type of vector is used as the item column should probably be retained, including numeric/integer/etc vectors. The way I'll do this is not to rely on acast's "turn vector into character and make that the rownames" behavior, but instead to keep track of indices.

I was actually going to implement it this way originally but when I was writing it I got lazy. Time to make it happen.