R 嵌套循环
嵌套循环
也可以将一个循环置于另一个循环内部。这被称为嵌套循环:
实例
打印列表中每个水果的形容词:
adj <- list("red", "big", "tasty")
fruits <- list("apple", "banana", "cherry")
for (x in adj) {
for (y in fruits) {
print(paste(x, y))
}
}
也可以将一个循环置于另一个循环内部。这被称为嵌套循环:
打印列表中每个水果的形容词:
adj <- list("red", "big", "tasty")
fruits <- list("apple", "banana", "cherry")
for (x in adj) {
for (y in fruits) {
print(paste(x, y))
}
}