Create a function that only shows the sum of whole numbers that are also multiples of 5 that are between the range 1,n.
So far, I got to the point where the function shows me the values that meet the above mentioned criteria, but all I gut are the Boolean values. Not sure of to change them to values so I can get the sum.
This is what I have:
sumnumbers <- function(n) {
multiples.5 <- c(1:n)
return(multiples.5 %% 5== 0)
}
sumnumbers (n = 15)
And this is what I get:
[1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE
On the other hand, if I change the code and add the sum to the function, I only get the number of instances where the criteria is met. Example:
sumanumbers <- function(n) {
multiples.5 <- c(1:n)
return(sum(multiples.5 %% 5== 0))
}
sumatoria (n = 15)
I get 3 when n = 15.