Files
R/amazing.R
2023-03-06 21:36:23 +02:00

34 lines
913 B
R

#Create vector from 1 to 10
num <- c(seq(1:10))
#Create empty vector named 'amazing'
amazing <-c()
#Iterate over all numbers from 1 to the length of the vector (10)
for (i in 1:length(num))
{
#If the number is greater or equal to 1 AND ALSO (&) smaller or equal to 3...
if(i >= 1 & i <=3)
# ^ this bit is important
{
cat(i, "is low\n")
#Add "low" to list called 'Amazing'
amazing[i] <- "low"
#Once this condition is satisfied, move on to next item in loop (if on 1, move on to 2, etc)
next
}
#If the number is greater or equal to 3 AND ALSO (&) smaller or equal to 6...
else if(i > 3 & i <=6)
# ^ this is like two IF's
{
cat(i, "is medium\n")
amazing[i] <- "medium"
next
}
else if(i > 6 & i <=10)
# ^ this bit is also important
cat(i, "is high\n")
amazing[i] <- "high"
next
}
amazing
sleep["Amazing"] <- amazing