I am trying to do the following operation in R for nrow=300,000 simulations (on ncol=30 variables):
down vote
accept
here's my code:
FS_DF <- read.csv("fs.csv", sep = ",")
Y_DF <- read.csv("Y.csv", sep = ",")
CALIBSCENS_DF <- read.csv("calib_scens.csv", sep = ",")
Y_DF$X <- NULL
X_mat <- matrix(1:1, nrow(CALIBSCENS_DF), nrow(FS_DF))
for (irow in 1:nrow(CALIBSCENS_DF)) {
for (jrow in 1:nrow(FS_DF)) {
for (krow in 1:ncol(FS_DF)) {
X_mat [irow, jrow] <- X_mat[irow, jrow] * (CALIBSCENS_DF[irow, krow] ^ FS_DF[jrow, krow])
}}}
fit <- .lm.fit(X_mat, as.matrix(sapply(Y_DF, as.numeric)))
Its taking forever to fill my X matrix. Can someone suggest a faster approach to do this operation. SCENS_DF, FS_DF are data frames. X_mat is a matrix.