[問題] 如何將lapply後的資料轉為一般資料格式

看板R_Language作者 (crucify)時間9年前 (2015/03/18 14:53), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 入門(寫過其他程式,只是對語法不熟悉) [問題敘述]: 我的資料是重複測量的資料,我用lapply選取出每一個人的最後四筆資料, 但我不知道該如何將他轉成一般的資料格式。 現在的資料,是這個樣子,按照ID分組的感覺: $fff4c5e1e7f914bce44c3457f7c2cd81 id duration M1 M2 M3 M4 M5 M6 1: fff4c5e1e7f914bce44c3457f7c2cd81 39 0 0 0 0 0 0 2: fff4c5e1e7f914bce44c3457f7c2cd81 40 0 0 0 0 0 0 3: fff4c5e1e7f914bce44c3457f7c2cd81 41 0 0 0 0 0 0 4: fff4c5e1e7f914bce44c3457f7c2cd81 42 0 0 0 0 0 0 $fff4e01e81b34213be876000a815389d id duration M1 M2 M3 M4 M5 M6 1: fff4e01e81b34213be876000a815389d 40 0 0 0 0 0 0 2: fff4e01e81b34213be876000a815389d 41 0 0 0 0 0 0 3: fff4e01e81b34213be876000a815389d 42 0 0 0 0 0 0 4: fff4e01e81b34213be876000a815389d 43 0 0 0 0 0 0 但我希望他可以合在一起: id duration M1 M2 M3 M4 M5 M6 1: fff4c5e1e7f914bce44c3457f7c2cd81 39 0 0 0 0 0 0 2: fff4c5e1e7f914bce44c3457f7c2cd81 40 0 0 0 0 0 0 3: fff4c5e1e7f914bce44c3457f7c2cd81 41 0 0 0 0 0 0 4: fff4c5e1e7f914bce44c3457f7c2cd81 42 0 0 0 0 0 0 1: fff4e01e81b34213be876000a815389d 40 0 0 0 0 0 0 2: fff4e01e81b34213be876000a815389d 41 0 0 0 0 0 0 3: fff4e01e81b34213be876000a815389d 42 0 0 0 0 0 0 4: fff4e01e81b34213be876000a815389d 43 0 0 0 0 0 0 [程式範例]: http://ideone.com/N911zU 以上是我打程式,資料s是長這樣: ID duration M1 M2 M3 M4 M5 M6 [1,] "0000da7e3f97f8323d2687daea605216" "1" "0" "0" "0" "0" "0" "0" [2,] "0000da7e3f97f8323d2687daea605216" "2" "0" "0" "0" "0" "0" "0" [3,] "0000da7e3f97f8323d2687daea605216" "3" "0" "0" "0" "0" "0" "0" [4,] "0000da7e3f97f8323d2687daea605216" "4" "0" "0" "0" "0" "0" "0" [5,] "0000da7e3f97f8323d2687daea605216" "5" "0" "0" "0" "0" "0" "0" 麻煩大家。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.126.55.194 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1426661628.A.F97.html

03/18 15:20, , 1F
do.call(rbind, yourList), rbindlist(yourList) (
03/18 15:20, 1F

03/18 15:20, , 2F
package: data.table)
03/18 15:20, 2F

03/19 11:48, , 3F
感謝...
03/19 11:48, 3F
文章代碼(AID): #1L2I3y-N (R_Language)
文章代碼(AID): #1L2I3y-N (R_Language)