dimanche 31 mars 2019

How to extract and use TRUE answers of one function in another

I need to create a function(y) where y is the specified number of multiples of three. For example, if 3 is inputted as y, then 3, 6 and 9 should be printed. My thought process was having a function(x) with an if statement to identify whether a number is a multiple of three or not and then using a which statement on the TRUE answers in function(x) in function(y)

This is my function(x):

f <- function(x) { if (any(x %% 3== 0)) { TRUE } else { FALSE } }

function(y) will be along the lines of a which statement where 3 is the first number displayed and then up to the number of specified multiples of three by using the TRUE answer in function(x) and will print each answer and stop once it is up to the specified number. I am just not too sure how to execute my thought process or if there is a better way to do this?

Aucun commentaire:

Enregistrer un commentaire