看板 R_Language 關於我們 聯絡資訊
google了很久,都沒辦法找到答案,因為英文不夠好,不知道如何把這個問題 用英文形容,因此上來發問 我現在有個dataframe id item1 item2 item3 a 香蕉 瑪奇朵 老虎 b 豆子 山葵 蘋果 想把這個dataframe打成像是 id a 香蕉 a 瑪奇朵 a 老虎 b 豆子 b 山葵 b 蘋果 我試著用reshape2裏頭的melt來做,做出來有點像是stack做出來的感覺 會變成 1 香蕉 2 瑪奇朵 3 老虎 4 豆子 5 山葵 6 蘋果 請問各位先輩有甚麼好的function或方法可以解決這個問題嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.173.98.170 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1463366825.A.A63.html
gbd37: http://pastie.org/10838886 05/16 11:15
gbd37: 有warning 但結果是一樣的 05/16 11:16
gbd37: 把每行都弄成character,就不會有warning了 05/16 11:22
celestialgod: 簡單補丸 http://pastebin.com/Ciw5j0mt 05/16 12:49
clansoda: 是的,我已經解決了,感謝大大的tidyr package 很有用 05/16 13:49
carl090105: melt function: http://pastebin.com/y7hQiz4N 05/16 20:53
clansoda: 突然想到,那有變回去的方法嗎? 05/17 17:42
celestialgod: tidyr::spread 05/17 17:52
wilson85771: tidyr真的好用 05/19 19:04
celestialgod: 其實就是reshape2的melt跟dcast,只是沒那麼方便 05/19 20:58
celestialgod: tidyr之前reshape2必學 05/19 20:59