2012-08-03 69 views
5

我想用時間 - 日記數據(美國時間使用調查)使用TraMineR在R做序列分析。我有數據作爲SPELL數據(ID,開始時間,停止時間,事件)使用時間日誌數據與TraMineR

Error in as.matrix.data.frame(subset(data, , 2)) : dims [product 0] do not match the length of object [9]

我相信這是與如何將我的時間(如字符),日期/時間類型:但我想,當將其轉換爲STS或SPS數據收到以下錯誤。我相信TraMineR需要POSIXlt格式?

這裏是我的原始數據的片段(trcode是事件)

head(atus.act.short)

 tucaseid tustarttim tustoptime trcode 
1 2.00701e+13 04:00:00 08:00:00 10101 
2 2.00701e+13 08:00:00 08:20:00 110101 
3 2.00701e+13 08:20:00 08:50:00 10201 
4 2.00701e+13 08:50:00 09:30:00 20102 
5 2.00701e+13 09:30:00 09:40:00 180201 
6 2.00701e+13 09:40:00 11:40:00 20102 

我用strptime的字符串轉換爲POSIXlt:

atus.act.short$starttime.new <- strptime(atus.act.short$tustarttim, format="%X") 
atus.act.short$stoptime.new <- strptime(atus.act.short$tustoptime, format="%X") 

我也切ID只有兩位數

atus.act.short$id <- atus.act.short$tucaseid-20070101070000 

我結束了一個新的數據幀如下:

id  starttime.new  stoptime.new trcode 
1 44 2012-08-03 04:00:00 2012-08-03 08:00:00 10101 
2 44 2012-08-03 08:00:00 2012-08-03 08:20:00 110101 
3 44 2012-08-03 08:20:00 2012-08-03 08:50:00 10201 
4 44 2012-08-03 08:50:00 2012-08-03 09:30:00 20102 
5 44 2012-08-03 09:30:00 2012-08-03 09:40:00 180201 
6 44 2012-08-03 09:40:00 2012-08-03 11:40:00 20102 
7 44 2012-08-03 11:40:00 2012-08-03 11:50:00 180201 
8 44 2012-08-03 11:50:00 2012-08-03 12:05:00 20102 
9 44 2012-08-03 12:05:00 2012-08-03 13:05:00 120303 
10 44 2012-08-03 13:05:00 2012-08-03 13:20:00 180704 
11 44 2012-08-03 13:20:00 2012-08-03 15:20:00 70104 
12 44 2012-08-03 15:20:00 2012-08-03 15:35:00 180704 
13 44 2012-08-03 15:35:00 2012-08-03 17:00:00 120303 
14 44 2012-08-03 17:00:00 2012-08-03 17:20:00 180701 
15 44 2012-08-03 17:20:00 2012-08-03 17:25:00 180701 
16 44 2012-08-03 17:25:00 2012-08-03 17:55:00 70101 
17 44 2012-08-03 17:55:00 2012-08-03 18:00:00 181203 
18 44 2012-08-03 18:00:00 2012-08-03 19:00:00 120303 
19 44 2012-08-03 19:00:00 2012-08-03 19:30:00 110101 
20 44 2012-08-03 19:30:00 2012-08-03 21:30:00 120303 
21 44 2012-08-03 21:30:00 2012-08-03 23:00:00 10101 
22 44 2012-08-03 23:00:00 2012-08-03 23:03:00 10201 
26 48 2012-08-03 06:45:00 2012-08-03 08:15:00 10201 
27 48 2012-08-03 08:15:00 2012-08-03 08:45:00 180209 
28 48 2012-08-03 08:45:00 2012-08-03 09:00:00 20902 
29 48 2012-08-03 09:00:00 2012-08-03 11:00:00 50101 
30 48 2012-08-03 11:00:00 2012-08-03 11:45:00 120312 

然後我嘗試創建的序列的對象[使用庫(佔美娜)]

atus.seq <- seqdef(atus.act.short, informat = "SPELL", id="id") 

我也得到以下錯誤:

Error in as.matrix.data.frame(subset(data, , 2)) : dims [product 0] do not match the length of object [9]

想法?

+0

我已經設法解決這個通過轉換的時間分鐘(以下計算器上的另一個問題),使得狀態碼字符(as.character),使用seqformat,並將其分配給時間軸。新代碼爲: 'atus.seq2 < - seqformat(atus.act.short2,id =「id」, from =「SPELL」,to =「STS」, begin =「startmin」,end =「stopmin 「,status =」trcode「, process =」FALSE「)' – mCorey 2012-08-06 19:52:00

+0

您可以將此作爲答案發布並接受爲正確答案嗎? – 2012-10-22 20:44:31

回答

4

我已經設法通過將時間轉換爲分鐘(在stackoverflow上的另一個問題之後),使狀態代碼成爲字符(as.character),使用seqformat並將其分配給時間軸來解決此問題。新的代碼讀取:

atus.seq2 <- seqformat(atus.act.short2, id="id", from="SPELL", to="STS", begin = "startmin", end = "stopmin", status="trcode", process = "FALSE")