Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list unique values for each column in a data frame

Suppose you have a very large input file in "csv" format. And you want to know the different values that occur in each column. How would you do that?

ex.

column1    column2    column3    column4
----------------------------------------
value11    value12    value13    value14
value21    value22    value23    value24
...
valueN1    valueN2    valueN3    valueN4

So I want my output to be something like:

column1 has these values: value11, value21, ...valueN1. but I don't need to see reoccurrences of the same value. I need this just to get an idea of what my data is all about.

like image 818
Mixalis Avatar asked Aug 15 '16 18:08

Mixalis


1 Answers

Let dat be your data frame after reading in the csv file, you can do

ulst <- lapply(dat, unique)

If you further want to know the number of unique values for each column, do

k <- lengths(ulst)
like image 84
Zheyuan Li Avatar answered Sep 18 '22 23:09

Zheyuan Li