Reputation: 23
I am currently doing a clustering exercise using TraMiner. I have a frequency table, df.seq
, that I broke into four clusters using the following code:
library(cluster)
df.om <- seqdist(df.seq, method='OM', indel=1, sm='TRATE', with.missing=TRUE)
clusterward <- agnes(df.om, diss=TRUE, method="ward")
df.cl4 <- cutree(clusterward, k=4)
cl4.lab <- factor(df.cl4, labels=paste("Cluster", 1:4))
Then, I plot a sequence frequency plot of my four clusters.
seqfplot(df.seq, group=cl4.lab, pbarw=FALSE, border=NA, withlegend = FALSE, yaxis = "pct", cpal=palette(rainbow(length(unique(df.new$cart)))))
While the seqfplot
gives a good visual, I would like to see a frequency table for each individual cluster. For example, I can do:
seqtab(df.seq)
and get the following output:
Sequence Frequency %
Item #1 10 30%
Item #2 9 25%
Item #3 8 20%
Any help would be extremely appreciated!
Upvotes: 1
Views: 763
Reputation: 3669
You can use by
. I illustrate using the actcal
data that ships with TraMineR
library(TraMineR)
data(actcal)
actcal.seq <- seqdef(actcal[,13:24])
seqfplot(actcal.seq, group=actcal$sex)
by(actcal.seq, actcal$sex, seqtab)
For your example the command would read
by(df.seq, cl4.lab, seqtab)
Hope this helps.
Upvotes: 1