I am looking up to index data frame by applying prime Number function on rows of data frame using apply. the given output should be holding out rows which have any or all numbers as prime. Example data frame name c4:
c1 c2 c3
1 8 2 6
2 9 5 4
3 10 4 5
4 7 1 8
5 3 1 2
6 7 5 9
7 5 1 4
8 2 1 3
9 7 2 4
10 10 4 8
the given output should be
c1 c2 c3
1 8 2 6
2 9 5 4
3 10 4 5
4 7 1 8
5 3 1 2
6 7 5 9
7 5 1 4
8 2 1 3
9 7 2 4
removing the tenth row. the code I am using for the prime number is
prime.function<-
function (x){
if(x == 2){
return(TURE)
} else if (any(x %% 2: (x - 1) == 0)){
return(FALSE)
}else{
return(TRUE)
}
}
and I am using the following function in apply function in base indexing :
c4[apply(c4, MARGIN = 1, FUN = function(x) any(prime.function(x))),]
but unfortunately, the code throws error.
I would love to hear any suggestion about the code. Hope I am clear on the explanation side.