I am trying to do sequence analysis using American Time Use Survey using TraMineR in R. I have data like SPELL data (id, start time, stop time, event), but I get the following error when trying to convert it to STS or SPS data:
Error in as.matrix.data.frame (subset (data, 2)): dims [product 0] do not match the length of the object [9]
I believe this has something to do with how I convert my time (as a character) to date / time types. I believe TraMineR requires POSIXlt format?
Here is a snippet of my source data (trcode is an event)
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
I use strptime to convert character strings to 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")
I also shorten the ID to two digits
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
[ (TraMineR)]
atus.seq <- seqdef(atus.act.short, informat = "SPELL", id="id")
:
as.matrix.data.frame( (, 2)): dims [product 0] [9]
?