Skip to content
Prev 363411 / 398502 Next

optimize the filling of a diagonal matrix (two for loops)

Hello

I have two for loops that I am trying to optimize... I looked for
vectorization or for using some funcions of the apply family? but really
cannot do it. I am writting my code with some small data set. With this
size there is no problem but sometimes I will have hundreds of rows so it
is really important to optimize the code. Any suggestion will be very
welcomed.

library("TSMining")
dataS = data.frame(V1 = sample(c(1,2,3,4),30,replace = T),
?????????????????? V2 = sample(c(1,2,3,4),30,replace =
T),
?????????????????? V3 = sample(c(1,2,3,4),30,replace =
T),
?????????????????? V4 = sample(c(1,2,3,4),30,replace =
T))
saxM = Func.matrix(5)
colnames(saxM) = 1:5
rownames(saxM) = 1:5
matrixPrepared = matrix(NA, nrow = nrow(dataS), ncol = nrow(dataS))

FOR(I IN 1:(NROW(DATAS)-1)){
? FOR(J IN (1+I):NROW(DATAS)){
??? MATRIXPREPARED[I,J] = FUNC.DIST(AS.CHARACTER(DATAS[I,]),
AS.CHARACTER(DATAS[J,]), SAXM, N=60)
? }
}
matrixPrepared

Thank you!


------
Aurora Gonz?lez Vidal
Phd student in Data Analytics for Energy Efficiency

Faculty of Computer Sciences
University of Murcia

@. aurora.gonzalez2 at um.es
T. 868 88 7866
www.um.es/ae