小编use*_*159的帖子

使用 Pivot long 对多个变量进行长数据透视

我正在尝试使用 Tidyr 的 Pivot_longer 将宽表数据重塑为长数据。但是,无法实现结果 - 尝试搜索但找不到确切的场景。

例子:

    x<- read.table(header=T, text='
   Dt1 V1_cur V2_cur V1_count V2_count  Other_1 
     A   10    6     50     10      Abc
     A   12    5     70     11      Xyz
     B   20    7     20     8       Axy
     B   22    8     22     9       Ax
   ')

# The result which I am trying to get is, to have one Character column with values Category-> values (V1,V2) and two measure columns Cur, Count.

# Dt1 Other_1 Category Cur Count
# A   Abc     V1       10   50 …
Run Code Online (Sandbox Code Playgroud)

r reshape melt tidyr

2
推荐指数
1
解决办法
1601
查看次数

标签 统计

melt ×1

r ×1

reshape ×1

tidyr ×1