2

我有一个包含 24 个TraMineR序列对象的列表。现在我想计算每个序列对象的最佳匹配距离(仅在每个对象内)并将其存储在一个新列表中,现在由 24 个 OM 距离对象(距离矩阵)组成。

数据集可以在这里找到。

library(TraMineR)
sequences <- read.csv(file = "event-stream-20-l-m.csv", header = TRUE, nrows=10)
repo_names = colnames(sequences)

# 1. Loop across and define the 24 sequence objects & store them in sequence_objects
colpicks <- seq(10,240,by=10)
sequence_objects <- mapply(function(start,stop) seqdef(sequences[,start:stop]), colpicks-    9, colpicks)

# 2. Calculate the costs for OM distances within each object 
costs <- mapply(seqsubm(sequence_objects, method="TRATE"))

# 3. Calculate the OM distance objects for each sequence object
sequences.om <- seqdist(sequence_objects, method="OM", indel=1, sm=costs, with.missing=FALSE, norm="maxdist")

步骤 (1) 工作正常,但是当我进行到步骤 (2) 时,它告诉我:

Error in seqsubm(sequence_objects, method = "TRATE") : 
[!] data is NOT a sequence object, see seqdef function to create one

这是很自然的,因为sequence_objects不是序列对象,而是序列对象的列表。

如何将该seqsubm函数应用于序列对象列表?

4

1 回答 1

2

我不熟悉这个TraMineR包,但是看起来你正在尝试迭代sequence_objects.

mapply用于同时迭代多个对象。
lapply相反,用于迭代单个对象。

因此,以下内容可能对您有用:

 costs <- lapply(sequence_objects, seqsubm, method="TRATE")
于 2013-04-05T17:52:46.337 回答