Kraken
Kraken

Reputation: 13

Time Series Hierarchical Clustering in R column-wise

I'm trying to doing a time series clustering using tsclust and my dataset looks like this: enter image description here

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): enter image description here

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

Answers (1)

Has QUIT--Anony-Mousse
Has QUIT--Anony-Mousse

Reputation: 77505

Transpose your data using t.

That converts columns into rows.

Upvotes: 3

Related Questions