将状态,ID和日期公式转换为有轨电车中的状态序列

时间:2017-04-10 11:35:16

标签: r traminer

virtual

我可以使用以下方式制作事件序列:

 library(TraMineR)  



    df2 <- structure(list(ID = structure(c(1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L), .Label = c("1", "2", "3", "4"), class = "factor"), 
    Date = structure(c(12432, 12432, 15262, 15293, 15385, 15385, 
    15475, 15567, 15598, 15628, 15689, 15810, 15871, 15963, 16024, 
    16054, 16144, 16205, 16297, 16389, 12432, 12492, 12614, 12676, 
    12767, 12888, 12949, 13071, 13132, 13253, 13344, 13406, 13436, 
    13559, 13618, 13709, 13771, 13862, 13953, 14045, 14137, 12432, 
    12676, 13010, 14045, 14137, 14228, 14290, 14410, 14502, 14563, 
    14714, 14744, 14744, 14775, 14836, 14897, 14897, 14928, 14958, 
    15048, 15201, 15232, 15323, 15414, 15536, 15536, 15536, 15567, 
    15567, 15598, 15628, 15659, 15659, 15751, 15751, 15779, 15810, 
    15810, 15840, 15871, 15871, 15901, 15901, 15963, 15993, 16054, 
    16054, 16085, 16116, 16144, 16144, 16175), class = "Date"), 
    st = structure(c(10L, 10L, 3L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 1L, 1L, 1L, 7L, 7L, 7L, 7L, 1L, 7L, 1L, 6L, 1L, 7L, 7L, 
    6L, 1L, 6L, 6L, 7L, 1L, 1L, 7L, 1L, 1L, 1L, 4L, 7L, 4L, 7L, 
    4L, 8L, 4L, 7L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L, 7L, 8L, 7L, 
    7L, 7L, 8L, 8L, 8L, 7L, 8L, 9L), .Label = c("1", "2", "3", 
    "4", "5", "6", "7", "8", "9", "10"), class = "factor")), class = "data.frame", row.names = c(NA, 
-93L), .Names = c("ID", "Date", "st"))

但是,我想获得一个用于绘图的状态序列。我可以通过减去日期等来将df2创建为SPELL格式,但随后我会松开日期(我相信这对于绘图来说更好)。或者我可以将ev <- seqecreate(id = df2$ID,timestamp = df2$Date,event = df2$st) 某种方式转换为状态序列吗?

1 个答案:

答案 0 :(得分:0)

要绘制序列,您可以

seqpcplot(ev)

为您提供以下平行坐标图

seqpcplot