Using R, I want to efficiently identify which values in a sequence are missing. I've written the below example of how I do it. There must be a better way. Can someone help?
data.list=c(1,2,4,5,7,8,9)
full.list=seq(from = 1, to = 10, by =1)
output <- c()
for(i in 1:length(full.list)){
holder1 <- as.numeric(any(data.list == i))
output[i] <- holder1
}
which(output == 0)
Step 1 : first we create two user input list. A & B Step 2 : Insert A and B to a set. Step 3 : for finding the missing values of first list we apply difference function, difference of B from A. Step 4 : for finding the Additional values of first list we apply difference function, difference of A from B.
How to Find a Missing Term in an Arithmetic Sequence. To find a missing term in an arithmetic sequence, first identify the common difference by subtracting any term from the term that comes immediately after it. Count up or down by this amount from term to term until you find the missing value needed.
Another possible solution
setdiff(full.list,data.list)
full.list[!full.list %in% data.list]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With