У меня есть список прогонов с весами для переменных (V1, V2, V5), которые я пытаюсь применить к своему входному файлу, а затем распечатать входной файл в текстовом документе. Кажется, что это было бы хорошим использованием для функции apply, но у меня нет опыта выполнения умножения матриц с подмножеством data.frame и последующего помещения этой функции в функцию apply.
# A list of runs with weights for 3 variables
run_table <- expand.grid(V1 = seq(0.5, 1.5, 0.5), V2 = seq(0.5, 1.5, 0.5), V5 = c(0,1))
# My input file (my input file has more columns and variables than this)
text1 <- c('various', 'text', 'values', 'for', 'input', 'files', 'a', 'b', 'c', 'd')
num <- c(4, 2, 2, 8, 16, 2, 8, 24, 8, 2)
name <- c('V1', 'V1', 'V1', 'V2', 'V3', 'V4', 'V4', 'V5', 'V5', 'V6')
input_file <- data.frame(text1, num, name)
# For each row in the run_table multiply the weight for variables V1, V2, & V5 by the value in input_file$num, then print the table to a text file
# Pseudo-code
for i to nrows(run_table)
run_table[i,]*input_file
write.table(input, file = paste0("input_", i, ".dat"), sep = " ", quote = F, row.names = F, col.names = F)