r - 无法在数据帧 r 闪亮中转置 1 行的 excel 文件
问题描述
我有一个包含 2 列的 excel 文件(第 1 列带有标题,第 2 列带有数据),我正在尝试将其转置(第 1 行带有标题,第 2 行带有数据)。出于某种原因,我的代码仅适用于 >= 2rows 的数据。
Input Excel:
Expected Output:
Code:
df <- df_customer_upload() # original excel file
df <- t(df_customer_upload()) # Transposed excel file, in matrix format
colnames(df) <- (df[1, ]) # Copies 1st row to the header
df <- df[-1,] # after copying 1st row as header, deletes the 1st row
View(df)
任何帮助,将不胜感激。提前致谢!!
解决方案
推荐阅读
- java - OAuth2 和 OAuth3 的区别?
- c# - 如何在 Unity 的另一个场景中访问游戏对象
- reactjs - 如何将用户重定向到其组织的网页
- javascript - 将 GET 结果保存在文本文件中会导致无限循环
- compiler-errors - 无法在 SWI prolog (Windows) 中运行我的代码
- sql-server - 在 SQL Server 2012 中启用“已提交的读取快照”是否需要重新映射我们的数据库表
- python-2.7 - Python2.7 - 使用 Python 向 https://www.aconvert.com/pdf/ 发出 GET 和 POST 请求
- file - Dropbox Online Only 文件重新下载
- visual-c++ - VC++,互斥体,但重复执行
- sockets - 如果没有 EOF,从 Golang 中的服务器读取 Unix 套接字响应的最佳方法是什么