将多列变成具有不同行和值的一列

时间:2018-09-22 21:08:30

标签: r dataframe

我有一个包含4列的数据框(df),并且希望将其整理成一个包含3列的数据框(df.neat)。

原始df:

    # A tibble: 121 x 4
    code Type1Err Type2Err Type3Err
   <int>    <dbl>    <dbl>    <dbl>
 1   501       37       23        1
 2   504       36       35        7
 3   507       24       37        1
 4   517       36       32        6
 5   520       24       32        2
 6   521        8        9        0
 7   524       20       40        3
 8   534       10       38        1
 9   543       21       28       10
10   544       19       15        3
# ... with 111 more rows

基本上,我希望df.neat包含列“代码”(501、504,...),“错误类型”(type1,type2,type3)和“错误编号”。预期df.neat:

# A tibble: X x X
    code Error_type Error_number 
   <int>    <dbl>    <dbl>    
 1   501     type1       37        
 2   501     type2       23        
 3   501     type3       1

我是R新秀,并不了解很多...我什至不知道这是否可能。我尝试了tidyr软件包,但未能使其正常工作。任何输入将不胜感激!

0 个答案:

没有答案
相关问题