I have been using t() to transpose a matrix especially when multiplying matrices. But I have always wondered the tidy way of doing this (tidyverse) and I suppose it is with pivot_wider() and pivot_longer(). In this case, I think I prefer the base way. Or am I mistaken? #rstats

Follow

@gabbspalomo I think of tidyverse as tools for dealing with datasets. Most of the time when I am transposing, it's not a dataframe, and rather a different type of task. And in that context, t() is perfectly good. If you are transposing a dataframe, then it would make sense to ask about a tidy way. And I think the best way for that is probably rotate_df() from sjmisc, which has tools designed to integrate seamlessly into tidy.

@mpanhans ohh I like this approach about datasets!!! Thanks Matt!!!

Sign in to participate in the conversation
Librem Social

Librem Social is an opt-in public network. Messages are shared under Creative Commons BY-SA 4.0 license terms. Policy.

Stay safe. Please abide by our code of conduct.

(Source code)

image/svg+xml Librem Chat image/svg+xml