横表变为竖表

library(tidyr)
from=c("O1","O2","O3")
D1=c(7,7,2)
D2=c(3,2,0)
D3=c(9,8,2)
D4=c(3,2,10)
df=data.frame(from,D1,D2,D3,D4)
df %>%
gather(to,flow,-from)

你可能感兴趣的:(横表变为竖表)