R remainder Function, Extract Specific Value

extract, function, modulo, r, vector

Solution

myfunction <- function(x,d) which(x%%d==0)
x <- 2:12
x[myfunction(x,3)]

Any particular reason you want to do this via a function? Otherwise you could just do

x[x%%3==0]

Problem

I'm working to write a function in R that gives out vectors of numeric indices where a vector divided by a number that has no remainder is listed in a resultant vector. this is what I have so far ``` myfunction <-function(x,d) { {y<- x%%d return(y)} } ``` if you input in: ``` myfunction(x=2:12,d=3) ``` the results comes out as: ``` [1] 2 0 1 2 0 1 2 0 1 2 0 ``` At the point that I am at, I am trying to extract all values of 0 since those indicate no remainder being present. I don't know how to go about doing that...

Original source