本文介绍了如何在R中转置tibble()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中, t()函数确实适用于矩阵。当我尝试用 t()转换小标题时,我得到一个矩阵。 tibble()不能使矩阵成小块。我最终花时间将列名称存储为变量,并在尝试重新制作标题的转置版本时附加它们。

In R the t() function is really meant for matrices. When I try to transpose my tibble with t() I end up with a matrix. A matrix can't be made into a tibble with tibble(). I end up spending time storing column names as variables and attaching them as I try to re-make a transposed version of my tibble.

问题:转置小标题的最简单方法是什么,其中第一列应成为新小标题的列名,而旧列名将成为我的第一列新小词。

Question: What is the simplest way to transpose a tibble where the first column should become the column names of the new tibble and the old column names become the first column of my new tibble.

推荐答案

如Sotos所提到的,您只需要重新声明矩阵即可。

As Sotos has mentioned it, you just need to re-declare your matrix as a tible:

as_tibble(cbind(nms = names(df), t(df)))

这篇关于如何在R中转置tibble()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 16:23