Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify missing values in a sequence / perform asymmetric difference between two lists

Tags:

r

missing-data

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)
like image 785
Dr. Beeblebrox Avatar asked Jun 23 '13 18:06

Dr. Beeblebrox


People also ask

How to find missing values between two lists in Python?

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 do you find the missing value of a sequence?

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.


2 Answers

Another possible solution

 setdiff(full.list,data.list)
like image 131
Geoffrey Absalom Avatar answered Sep 19 '22 13:09

Geoffrey Absalom


full.list[!full.list %in% data.list]
like image 40
Hong Ooi Avatar answered Sep 21 '22 13:09

Hong Ooi