# How to find mathematical set using a data frame column in R?

A mathematical set is a collection of unique elements or a collection of elements that are different from each other. If we want to find a mathematical set using a data frame column then we can simply use unique function.

For Example, if we have a data frame called df that contains a column say X then we can find the mathematical set using X with the help of below command −

## Output

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

[1] 7 3 5 6 4 0 2


## Example 2

Following snippet creates a sample data frame −

y<-round(rnorm(20),1)
df2<-data.frame(y)
df2

The following dataframe is created

     y
1  -0.4
2   0.0
3   1.3
4   0.6
5  -1.2
6   0.4
7  -0.4
8   0.8
9   0.2
10  0.2
11  0.8
12  1.2
13 -1.6
14  2.2
15  0.9
16 -0.4
17 -0.3
18  0.2
19 -0.3
20  0.5

To find mathematical set using column y of df2 on the above created data frame, add the following code to the above snippet −

y<-round(rnorm(20),1)
df2<-data.frame(y)

## Output

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

[1] 3 6 1 4 2