See the bellow example:
x = cat('hi\n')
# hi
print(x)
# NULL
With the help of the above example, what I am trying to tell you is that in R programming, every function has to return something. The cat prints the output in the console and returns NULL, those NULL are returned as output from print_info function.
Instead of using cat or print in the function, you could use paste/paste0
print_info <- function(x) {
paste0("\nThe average temperature is ", mean(x))
}
cat(sapply(temp, print_info))
#The average temperature is 4.8
#The average temperature is 9
#The average temperature is 2.2
#The average temperature is 2.4
#The average temperature is 5.4
#The average temperature is 4.6
#The average temperature is 4.6