Advertisement
celestialgod

stack columns

May 15th, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.28 KB | None | 0 0
  1. library(dplyr)
  2. library(tidyr)
  3. dat <- data.frame(id = c('a','b'), item1 = c('香蕉','豆子'),
  4.                   item2 = c('瑪奇朵','山葵'), item3 = c('老虎','蘋果'),
  5.                   stringsAsFactors = FALSE)
  6. dat %>% gather(item,n,-id) %>% arrange(id) %>% select(-item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement