# Find the missing numbers in a sequence in R data frame column.

To find the missing numbers in a sequence in R data frame column, we can use setdiff function.

For Example, if we have a data frame called df that contains a column say X and we want to check which values between 1 to 20 are missing in this column then we can use the below command −

## Output

If you execute all the above given snippets as a single program, it generates the following Output −

[1] 2 3 8 9 10


## Example 2

Following snippet creates a sample data frame −

y<-c(1:3,5:10,21:30,35)
df2<-data.frame(y)
df2

The following dataframe is created

   y
1  1
2  2
3  3
4  5
5  6
6  7
7  8
8  9
9  10
10 21
11 22
12 23
13 24
14 25
15 26
16 27
17 28
18 29
19 30
20 35

To find the missing numbers between 1 and 35 in y on the above created data frame, add the following code to the above snippet −

y<-c(1:3,5:10,21:30,35)
df2<-data.frame(y)

## Output

If you execute all the above given snippets as a single program, it generates the following Output −

[1]  1 2 5 6 8 10 11 12 13 14 15 16 17 18 19 20 21 23 24
[20] 25 27 28 29 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45
[39] 46 49 50 52 53 54 55 56 57 58 59 60 62 63 64 65 66 67 68
[58] 70 71 72 73 74 75 76 77 79 82 83 85 86 88 89 90 92 93 94
[77] 95 96 98 100