Mixalis Mixalis - 2 months ago 4x
R Question

Get the different values from columns R

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?


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.


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)