每当我尝试在已使用seqformat转换为STS格式的数据上运行seqdef时,我都会看到此错误。我的数据框样本看起来像
head(df.new, 10)
user_id orderdate cart to
1 8 1 produce 30
2 8 31 produce 60
3 8 61 produce 70
4 8 71 produce 92
5 10 1 produce 30
6 10 31 produce 42
7 10 43 meat seafood 56
8 10 57 deli 77
9 17 1 beverages 3
10 17 4 beverages 8
它总共有14000行订单,并且每个用户在同一天发生了一些订单(即orderdate == to)。下面是我用来创建STS数据的代码,用作seqdef的输入。
df.form <- seqformat(df.new, id='user_id', begin='orderdate', end='to', status='cart', from='SPELL', to='STS', process=FALSE)
df.seq <- seqdef(df.form, left='DEL', right = 'unknown', xtstep=10, void = 'unknown')
运行seqdef时收到的错误消息是
[>] found missing values ('NA') in sequence data
[>] preparing 35000 sequences
[>] coding void elements with 'unknown' and missing values with '*'
[>] 21 distinct states appear in the data:
1 = alcohol
2 = babies
3 = bakery
4 = beverages
5 = breakfast
6 = bulk
7 = canned goods
8 = dairy eggs
9 = deli
10 = dry goods pasta
11 = frozen
12 = household
...
[>] adding special state(s) to the alphabet: unknown
Error in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
factor level [24] is duplicated
我尝试删除orderdate == to的那些订单,但仍然会出现相同的错误。我将不胜感激,我可以帮助解决这个问题。感谢。
答案 0 :(得分:0)
发生错误是因为您使用相同的代码(&#39;未知&#39;)来表示正确的错误和空洞。
如果序列中包含&#39; missings&#39;,当您在with.missing = TRUE
或seqdist
等函数中设置seqdplot
时,这些缺失将被视为单独的状态,而空格用于调整行长度,在绘制序列(seqplot
)或计算相异度(seqdist
)时会被忽略。