Reputation: 13
I'm trying to doing a time series clustering using tsclust and my dataset looks like this:
I have over 500 time series with eight observations each on the same time line. I applied tsclust to it but got clusters by time but not by series(As below):
Later I found out tsclust can only work Row-wise.(from www.rdocumentation.org/packages/dtwclust/versions/3.1.1/topics/tsclust)
If there's any other similar functions that I can use to finish the clustering analysis? Or how I can change the format of my data to do it?
my original code looks like this:
tst<-read.csv("data.csv", stringsAsFactors = TRUE)
tst<-xts(tst[,-1], order.by = as.Date(paste0(tst[,1])))
par(mar=c(1,1,1,1))
plot.xts(tst)
series <- zscore(tst)
hc.sbd <- tsclust(series, type = "h", k = 6L,
preproc = zscore, seed = 233,
distance = "sbd", centroid = shape_extraction,
control = hierarchical_control(method = "average"))
plot(hc.sbd)
plot(hc.sbd, type = "sc")
Any help is appreciated. Thank you in advance.
Upvotes: 0
Views: 1151
Reputation: 77505
Transpose your data using t
.
That converts columns into rows.
Upvotes: 3