[問題類型]:
程式諮詢(我想用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"
麻煩大家。