Use R:There is a numeric vector of integers; every elementappears twice except for one Implement the function findUnique() tofind the element that appears only once in the numeric vector usingloop. Implement the function findUnique2() to find the element thatappears only once in the numeric vector without using loop. datavec<- c(3, 5, 2, 7, 7, 13, 13, 2, 8, 1, 3, 1, 5) sample output is8
A <- function(s){
for(x in 1:length(s)){
found <- FALSE
for(j in 1:length(s)){
if(x!=j){
if(s[x]==s[j]){
found<- TRUE
break
}
}
}
if(!found){
return(s[x])
}
}
}
Solution
CODE:
findUnique <- function(s){
#take each element and compare with other and check found ornot
for(x
OR
OR