0
下面是一個簡單的代碼:R控制結構雙迴路
for (i in c("red", "green"))
for (j in c("blood", "trees")) {
k <- paste(i, j, sep=" ")
print(k)
}
}
我將它想只輸出"red blood"
和"green trees"
。剩下的組合將被丟棄。這可以在循環內完成嗎?
下面是一個簡單的代碼:R控制結構雙迴路
for (i in c("red", "green"))
for (j in c("blood", "trees")) {
k <- paste(i, j, sep=" ")
print(k)
}
}
我將它想只輸出"red blood"
和"green trees"
。剩下的組合將被丟棄。這可以在循環內完成嗎?
你並不需要一個循環:
R> paste(c("red","green"), c("blood","trees"))
[1] "red blood" "green trees"