interpolation with matrices in R
问题 I want to use linear interpolation to create a large matrix from 2 smaller matrices. I can do this using a function like this: mat1 <- matrix(rep(20, 4), ncol = 2) mat2 <- matrix(seq(21, 24, 1), ncol = 2) mat3 <- matrix(c(18, 27, 25, 12), ncol = 2) num.days <- c(31, 29) interpolate <- function(initial, final, n){ data.list <- list() for (i in 1:(n - 1)){ step1 <- (final - initial) / n step2 <- step1 * i data.list[[1]] <- initial data.list[[i+1]] <- round(step2 + initial, 2) } newmat = do.call