如何创建一个给定正整数的函数,returns 一个存在 5 的倍数的向量?

How to create a function that given a positive integer, returns a vector with the numbers multiples of 5 that exist?

我必须创建一个 mult5 函数,给定一个正整数,return 是一个包含小于或等于该数字的 5 倍数的向量。例如,对于数字 17,mult5 (17) 应该 return 向量 (0, 5, 10, 15)。我不能使用任何类型的循环或 sapply / lapply.

我想我可以用 seq 函数来做,但我不知道怎么做。这就是我尝试过的:

mult5 <- function(numero){
  modulo = numero %% 5 == 0
  seq = seq(from = 0, to = numero, by = modulo)
}

但我认为我不能将变量放入序列函数中并抛出错误。 有人可以解释或告诉我我可以做什么吗?

测试:

is.list(mult5(24)) == FALSE
all(mult5(24) == c(0, 5, 10, 15, 20))
check.not.command("for", mult5)
check.not.command("while", mult5)

我不会用for/while。

错误信息:

 Error in seq.default(from = 0, to = numero, by = modulo) : 
  invalid '(to - from)/by' 

那是我的例子:

def check(number: int):
    lst = list(range(0, number, 5))
    print(lst)

根据@diggusbickus 建议编辑

如果 numero 不是 5 的倍数,seq 函数已经具有您需要的行为,因此您可以将代码简化为:

mult5 <- function(numero){
  seq(from = 0, to = numero, by = 5)
}