The following code prints the first five whole numbers one line at a time:
for (i in 1:5){
print(i)
}
seq(1, 9, by = 2)
to print the first five odd numbers squared one line at a time. Use a
descriptive variable to identify the index values such as for (odd in
odds)
.for
loop from task 3 to paste()
and print a statement for
each odd number in the form “odd
squared is odd_squared
”.Create a vector of a seq()
of numbers from 5 to 50 by 5 and use it in a
for
loop to generate another vector of those numbers squared. Your for
loop should look something like:
output <- c()
for (number in _____) {
_____ <- _____^2
output <- c(output, number_squared)
}