display all unique values from a variable in r

You can display all unique values from a variable in R using the unique() function. This function returns a vector of unique values in the order in which they appear in the original vector.

Here's an example:

main.r
# create an example vector with repeated values
my_vector <- c(1, 2, 3, 2, 4, 3, 5, 1, 6, 7, 5)

# use the unique function to get unique values
unique_values <- unique(my_vector)

# print the unique values
print(unique_values)
227 chars
9 lines

This will output:

main.r
[1] 1 2 3 4 5 6 7
18 chars
2 lines

Note that the unique() function can also be used with data frames and other data structures in R.

gistlibby LogSnag