dplyr mutate and transmute do not preserve rownames

2,583 views
Skip to first unread message

Erich Neuwirth

unread,
Oct 2, 2014, 10:41:28 AM10/2/14
to manip...@googlegroups.com
AFAIK mutate and transmute at the moment do not preserve rownames. I am doing some work where this would be rather convenient.
Is this something which would be worth adding, at least as a option?

Hadley Wickham

unread,
Oct 2, 2014, 10:43:14 AM10/2/14
to Erich Neuwirth, manipulatr
No, dplyr will never preserve rownames. I think rownames make sense
for matrices, but not for data frames. Make them an explicit variable.

Hadley
> --
> You received this message because you are subscribed to the Google Groups
> "manipulatr" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to manipulatr+...@googlegroups.com.
> To post to this group, send email to manip...@googlegroups.com.
> Visit this group at http://groups.google.com/group/manipulatr.
> For more options, visit https://groups.google.com/d/optout.



--
http://had.co.nz/

Romain Francois

unread,
Oct 2, 2014, 10:44:00 AM10/2/14
to Erich Neuwirth, manip...@googlegroups.com
You can add an additional column to carry names. dplyr does not support rownames. 

Romain

Envoyé de mon iPhone

Le 2 oct. 2014 à 16:41, Erich Neuwirth <neuwir...@gmail.com> a écrit :

AFAIK mutate and transmute at the moment do not preserve rownames. I am doing some work where this would be rather convenient.
Is this something which would be worth adding, at least as a option?

--

Erich Neuwirth

unread,
Oct 4, 2014, 7:09:16 PM10/4/14
to manip...@googlegroups.com
I understand that dplyr cannot in general support rownames because it does not make sense with, say, summarize. But it would make sense with transmute and mutate, since these operations preserve row structure. Therefore I humbly ask if that is something which could be considered worth adding to dplyr.

Erich Neuwirth

unread,
Oct 4, 2014, 8:12:19 PM10/4/14
to manip...@googlegroups.com
OK,
I just saw Hadley's authoritative statement.
The problem in fact occurred because I had a chain which in the end converted the result to a matrix
and the matrix did not habve rownames.
The underlying reason is:
I can apply the round function to a dataframe with only numeric variables.
If the dataframe contains character variables (playing the role of rownames)
applying the round function fails. 
If the dataframe had rownames, I would not need
to use a character variable and therefore could 
apply the round function.

Converting to a matrix also would imply that I add the rownames manually
since I cannot get the from the dataframe.


Reply all
Reply to author
Forward
0 new messages