首页 > 解决方案 > 无法在数据帧 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)

我得到的输出: 在此处输入图像描述

任何帮助,将不胜感激。提前致谢!!

标签: rdataframeshinyshiny-server

解决方案


推荐阅读