从SPELL数据创建序列对象 [英] Creating a sequence object from SPELL data

查看:80
本文介绍了从SPELL数据创建序列对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SPELL格式使用seqdef创建一个序列对象.这是我的数据示例:

I am trying to create a sequence object with seqdef using SPELL format. Here is an example of my data:

spell <- structure(list(ID = c(1, 3, 3, 4, 5, 5, 6, 8, 9, 10, 11, 11, 
12, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 
15, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 
19), status = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 2, 3, 1, 2, 3, 2, 3, 1, 1, 1, 3, 1, 3, 3, 1, 3, 1, 1, 1, 
1, 1, 3, 3, 1, 3, 1, 1, 1), time1 = c(1, 1, 57, 1, 1, 91, 1, 
1, 1, 1, 1, 104, 1, 1, 60, 109, 121, 1, 42, 47, 54, 64, 72, 78, 
85, 116, 1, 29, 39, 69, 74, 78, 88, 1, 16, 40, 68, 1, 30, 123, 
1, 39, 51, 1, 61), time2 = c(125, 57, 125, 125, 91, 125, 125, 
125, 125, 125, 104, 125, 125, 60, 109, 121, 125, 42, 47, 54, 
64, 72, 78, 85, 116, 125, 29, 39, 69, 74, 78, 88, 125, 16, 40, 
68, 125, 30, 123, 125, 39, 51, 125, 61, 125)), .Names = c("ID", 
"status", "time1", "time2"), row.names = c(NA, 45L), class = "data.frame")

当我尝试定义序列对象时,抛出一个奇怪的错误:

When I try to define the sequence object, a strange error is thrown:

spell.seq <- seqdef(data=spell, informat="SPELL", id="ID", begin="time1", end="time2", 
                    status="status", limit=125,process=FALSE)

 [>] time axis: 1 -> 125
 [>] SPELL data converted into 17 STS sequences
 [>] 3 distinct states appear in the data: 
     1 = 1
     2 = 2
     3 = 3
 [>] state coding:
       [alphabet]  [label]  [long label] 
     1  1           1        1
     2  2           2        2
     3  3           3        3
 [>] 17 sequences in the data set
 [>] min/max sequence length: 125/125
Error in `row.names<-.data.frame`(`*tmp*`, value = value) : 
  invalid 'row.names' length

但是,如果我通过seqformat间接执行相同的操作,并保留相同的参数,则不会引发错误:

However, if I do the same indirectly via seqformat, preserving the same arguments, no error is thrown:

sts <- seqformat(data=spell,from="SPELL",to="STS",
                 id="ID",begin="time1",end="time2",status="status",
                 limit=125,process=FALSE)

seqs <- seqdef(sts,right="DEL")

将TraMineR 1.8-5与R 3.0.0 Windows 7 64位一起使用.这是一个错误还是我做错了什么?提前致谢.

Using TraMineR 1.8-5 with R 3.0.0 Windows 7 64-bit. Is this a bug or am I doing something wrong? Thanks in advance.

推荐答案

快速查看seqdef()的来源以了解如何设置row.names,显示它们是根据id参数的值进行设置的.

A quick look at the source of seqdef() for how the row.names are set shows they are set based on the value of the id argument.

?seqdef中查找id节目

id
可选参数,用于设置序列对象的行名. 如果为NULL(默认值),则从输入数据中获取行名.如果设置为"auto",则序列的编号从1到序列号.也可以指定长度等于序列数的行名向量.

id
optional argument for setting the rownames of the sequence object. If NULL (default), the rownames are taken from the input data. If set to "auto", sequences are numbered from 1 to the number of sequences. A vector of rownames of length equal to the number of sequences may be specified as well.

从问题示例中,您正在传递不符合这些条件的id="ID".将其更改为id=NULL可使命令按预期完成,并使用identical( spell.seq, seqs)检查是否相等将产生true.

From the example in the question you are passing id="ID" which does not meet these criteria. Changing this to id=NULL allows the command to complete as expected and a check for equality using identical( spell.seq, seqs) yields true.

这篇关于从SPELL数据创建序列对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆