r - Looping through sequence objects in a list? -
i have list contains 24 traminer sequence objects. want calculate optimal matching distances each of these sequence objects (only within each object) , store in new list, consisting of 24 om distance objects (distance matrices).
the dataset can found here.
library(traminer) sequences <- read.csv(file = "event-stream-20-l-m.csv", header = true, nrows=10) repo_names = colnames(sequences) # 1. loop across , define 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 costs om distances within each object costs <- mapply(seqsubm(sequence_objects, method="trate")) # 3. calculate om distance objects each sequence object sequences.om <- seqdist(sequence_objects, method="om", indel=1, sm=costs, with.missing=false, norm="maxdist") step (1) works fine, when progress step (2), tells me:
error in seqsubm(sequence_objects, method = "trate") : [!] data not sequence object, see seqdef function create 1 this natural, because sequence_objects not sequence object, list of sequence objects.
how can apply seqsubm function list of sequence objects?
i'm not familiar traminer package, looks trying iterate on elements of sequence_objects.
mapply iterating on multiple objects simultaneously.
lapply in contrast iterating on single object.
therefore, following might work you:
costs <- lapply(sequence_objects, seqsubm, method="trate")
Comments
Post a Comment