在dplyr

时间:2016-06-23 21:12:52

标签: r dplyr

我对dplyr比较熟悉,但我遇到了以下问题。我有下表。

Issue      Rejected Accepted

Issue 1    2        4
Issue 2    3        6
Issue 3    0        1

我想要做的是创建一个新列(决策),它将接受和拒绝作为条目。所以我想要做的就是将其改为以下内容,

Issue   Decision    Quantity

Issue 1 Rejected    2
Issue 1 Accepted    4
Issue 2 Rejected    3
Issue 2 Accepted    6
Issue 3 Rejected    0
Issue 3 Accepted    1

1 个答案:

答案 0 :(得分:1)

library(dplyr)
library(tidyr)
df1 <- gather(df, Issue)
colnames(df1)[2:3] <- c("Decision", "Quantity") 

df1 %>% arrange(Issue)