假设我们有两个向量,但长度不同:
s <- seq(from = 1, to = 10, by = 1)
w <- seq(from = 1, to = 100, by = 1)
result <- matrix(numeric(0), nrow = length(s), ncol = length(w))
如何以不将for循环地将s的每个元素除以w的每个元素来执行逐元素除法的方法。下面是for循环解决方案。
for (i in 1:length(s)){
result[i,] <- (w / s[i])}
非常感谢,