I am dealing with a number of time-series consisting of 2250 samples of flow velocity in 2D (Vx, Vy).
For each time-series I have determined the resultant vector angle (d) and magnitude (Vres) based on the ensemble means of Vx and Vy and now want to rotate each point in the time-series by d so that mean(Vx)=Vres and mean(Vy)=0. Here is the code I have written to perform the rotation for a single time-step: n <- 2250 #number of samples in time series R <- matrix ((c ((cos(d)), (-sin(d)), (sin(d)), (cos(d)))), 2) #rotation matrix, where d is the resultant vector angle in degrees V <- t (matrix ((c (Vx, Vy)), n)) #velocity matrix Vadj <- R %*% (V) [, 1] #e.g. for the first Vx, Vy pair in the time-series Now what I want to do is loop this to give me the solution at each time-step and then append the adjusted Vx and Vy time-series to a new matrix. Can someone please suggest how I should about this? Thanks, Martin -- View this message in context: http://r.789695.n4.nabble.com/Looping-matrix-multiplication-tp4648881.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.