Существует встроенный вектор с названиями месяцев: month.name
.
Чтобы создать for
l oop, просто введите:
for(i in month.name) {...}
Чтобы проверить, является ли месяц март или апрель, используйте %in%
, например:
if (i %in% c("March", "April") {...}
Таким образом, ваш код может быть:
for(i in month.name) {
if (i %in% c("March", "April")) {
print(paste(i, "- you are an Aries."))
} else {
print(paste(i, "- you are not in Aries."))
}
}
#> [1] "January - you are not in Aries."
#> [1] "February - you are not in Aries."
#> [1] "March - you are an Aries."
#> [1] "April - you are an Aries."
#> [1] "May - you are not in Aries."
#> [1] "June - you are not in Aries."
#> [1] "July - you are not in Aries."
#> [1] "August - you are not in Aries."
#> [1] "September - you are not in Aries."
#> [1] "October - you are not in Aries."
#> [1] "November - you are not in Aries."
#> [1] "December - you are not in Aries."
Создано 09.07.2020 пакетом REPEX (v0.3.0)