Use this tag for questions related to Distinct Values, i.e. values that are distinct/unique from the values in a collection.
Questions tagged [distinct-values]
632 questions
656
votes
34 answers
Java 8 Distinct by property
In Java 8 how can I filter a collection using the Stream API by checking the distinctness of a property of each object?
For example I have a list of Person object and I want to remove people with the same name,
persons.stream().distinct();
Will use…

RichK
- 11,318
- 6
- 35
- 49
127
votes
7 answers
How to maintain a Unique List in Java?
How to create a list of unique/distinct objects (no duplicates) in Java?
Right now I am using HashMap to do this as the key is overwritten and hence at the end we can get HashMap.getKeySet() which would be unique. But I am sure…
user1804287
118
votes
7 answers
List distinct values in a vector in R
How can I list the distinct values in a vector where the values are replicative? I mean, similarly to the following SQL statement:
SELECT DISTINCT product_code
FROM data

Mehper C. Palavuzlar
- 10,089
- 23
- 56
- 69
96
votes
12 answers
Counting unique / distinct values by group in a data frame
Let's say I have the following data frame:
> myvec
name order_no
1 Amy 12
2 Jack 14
3 Jack 16
4 Dave 11
5 Amy 12
6 Jack 16
7 Tom 19
8 Larry 22
9 Tom 19
10 Dave …

Mehper C. Palavuzlar
- 10,089
- 23
- 56
- 69
59
votes
4 answers
select distinct items from a column in powershell
If I issue following command in PowerShell, I get a lot of rows back.
PS C:\Users\benh> get-command
CommandType Name ModuleName Definition
----------- ---- …

Ben H
- 3,136
- 3
- 25
- 34
43
votes
2 answers
pyspark: count distinct over a window
I just tried doing a countDistinct over a window and got this error:
AnalysisException: u'Distinct window functions are not supported:
count(distinct color#1926)
Is there a way to do a distinct count over a window in pyspark?
Here's some example…

Bob Swain
- 3,052
- 3
- 17
- 28
43
votes
6 answers
Spark DataFrame: count distinct values of every column
The question is pretty much in the title: Is there an efficient way to count the distinct values in every column in a DataFrame?
The describe method provides only the count but not the distinct count, and I wonder if there is a a way to get the…

Rami
- 8,044
- 18
- 66
- 108
34
votes
6 answers
Selecting distinct 2 columns combination in mysql
I have a mysql table that looks like this:
1 value1 value2 3534
2 value1 value1 8456
3 value1 value2 3566
4 value1 value3 7345
5 value2 value3 6734
I need a query to select all the rows with distinct column 2…

James Harzs
- 1,853
- 5
- 21
- 30
28
votes
4 answers
Get distinct list between two lists in C#
I have two lists of strings. How do I get the list of distinct values between them or remove the second list elements from the first list?
List list1 = { "see","you","live"}
List list2 = { "see"}
The result should be…

kartal
- 17,436
- 34
- 100
- 145
25
votes
3 answers
get Distinct Values with Sorted Data
I need a Query to get distinct keys with sorted on basis of score in Mongodb 1.6.5
I have records Like
{key ="SAGAR"
score =16
note ="test1"
}
{key ="VARPE"
score =17
note ="test1"
}
{key ="SAGAR"
score =16
note ="test2"
}
{key ="VARPE"
score…

Sagar Varpe
- 3,531
- 4
- 27
- 43
22
votes
4 answers
R: How do I choose which row dplyr::distinct() keeps based on a value in another variable?
The real life problem: I have subjects with MRI scan data. Some of which have been scanned multiple times (separate rows). Some of those were scanned under different protocols each time. I want to keep all unique rows by subject ID, and if a subject…

Bart
- 473
- 6
- 15
21
votes
7 answers
Creating distinct list from existing list in Java 7 and 8?
If I have:
List listInts = { 1, 1, 3, 77, 2, 19, 77, 123, 14, 123... }
in Java what is an efficient way of creating a List listDistinctInts containing only the distinct values from listInts?
My immediate thought is to create a…

Matt Coubrough
- 3,739
- 2
- 26
- 40
19
votes
8 answers
How to generate list of unique random floats in Python
I know that there are easy ways to generate lists of unique random integers (e.g. random.sample(range(1, 100), 10)).
I wonder whether there is some better way of generating a list of unique random floats, apart from writing a function that acts like…

Simon
- 342
- 1
- 2
- 10
19
votes
4 answers
How to use Distinct function in influxDB
I am using influx DB and issuing command,
SELECT * FROM interface
Below is the out put-
interface
time element path value
2016-08-24T21:22:16.7080877Z …

Ammad
- 4,031
- 12
- 39
- 62
19
votes
4 answers
Trying to sum distinct values SQL
I'm having trouble coming up with a value for a cell in SSRS, which should be a sum of distinct values. I have a SSRS report that looks similar to the below screenshot:
I'm having trouble getting the value in red ($11.25). I basically need to sum…

kyle_13
- 1,173
- 6
- 25
- 47