Questions tagged [distinct-values]

Use this tag for questions related to Distinct Values, i.e. values that are distinct/unique from the values in a collection.

632 questions
8
votes
3 answers

How to count distinct values in a list in linear time?

I can think of sorting them and then going over each element one by one but this is nlogn. Is there a linear method to count distinct elements in a list?
polerto
  • 1,750
  • 5
  • 29
  • 50
7
votes
2 answers

Count all the words in a file using java Streams

I was trying to count the number of unique words in a text file. For the sake of simplicity, my current file content is: This is a sample file My attempt is: long wordCount = Files.lines(Paths.get("sample.txt")) .map(line ->…
user10824969
7
votes
3 answers

efficient count distinct across columns of DataFrame, grouped by rows

What is the fastest way (within the limits of sane pythonicity) to count distinct values, across columns of the same dtype, for each row in a DataFrame? Details: I have a DataFrame of categorical outcomes by subject (in rows) by day (in columns),…
C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
7
votes
3 answers

How to get distinct list of object with concat in Java 8

I have 2 Java Classes. class A { String name; List numbers; } class B { Integer number; } I want to get the distinct of Class A and concat the List of B in it. e.g. Suppose I have a List with the following objects. List{ name = "abc" …
7
votes
3 answers

SQL Conditional Case

I have a table that lists items and a status about these items. The problem is that some items have multiple different status entries. For example. HOST Status 1.1.1.1 PASS 1.1.1.1 FAIL 1.2.2.2 FAIL 1.2.3.3 …
Eddie D
  • 111
  • 3
  • 8
6
votes
2 answers

How to count each instance of distinct-values in XQuery?

I have an XML file with the following elements and attributes: How do I get the count of 1) distinct occurrences of each attribute color and 2)…
ritzdiamond
  • 269
  • 1
  • 2
  • 17
6
votes
4 answers

Is it possible to select columns in r based on any value in the column?

I want to subset my df to include only columns that include a certain value in any row. for example, if I have: year = c(1990,1991,1992,1993,1994,1995,1996,1997,1998,1999) apple = c(1,4,6,8,9,9,2,4,7,4) orange = c(7,1,5,5,2,1,7,1,3,8) banana =…
Emily
  • 75
  • 5
6
votes
3 answers

Abbreviation of Strings that Remains Unique

I have a unique list of strings (the original idea was the column names in a table). The task is to perform a maximal possible abbreviation of the list, so the list remains distinct. For example AAA, AB can be abbreviated to AA, AB. (But not to A,…
Marmite Bomber
  • 19,886
  • 4
  • 26
  • 53
6
votes
1 answer

Select Distinct Array Values from Postgresql Table

I have a PostgreSQL database table which looks like this content title category content Hello World ["Great"] This is the content Learn More ["Learn", "Great"] Learn about things I know this is not the…
Jordash
  • 2,926
  • 8
  • 38
  • 77
6
votes
1 answer

Laravel 5.4 need to get distinct records through eloquent relation

I have a table "transactions". in that table I have multiple columns which are id, user_id, customer_name, restaurant_name and time-stamps also. What I need is if I have two or three same records in the table means restaurant_name is repeating with…
user8499429
  • 67
  • 1
  • 1
  • 6
6
votes
3 answers

druid vs Elasticsearch

I'm new to druid. I've already read "druid VS Elasticsearch", but I still don't know what druid is good at. Below is my problem: I have a solr cluster with 70 nodes. I have a very big table in solr which has 1 billion rows, and each row has 100…
zhouxiang
  • 153
  • 3
  • 12
5
votes
3 answers

NSFetchRequest with distinct properties

I'm trying to get a distinct result from NSPredicate. My code: NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Members" inManagedObjectContext:context]; …
Rui Lopes
  • 2,562
  • 6
  • 34
  • 49
5
votes
1 answer

Find distinct values group by another field mongodb

I have collection with documents like this : { "_id" : ObjectId("5c0685fd6afbd73b80f45338"), "page_id" : "1234", "category_list" : [ "football", "sport" ], "time_broadcast" : "09:13" } { "_id" :…
Wiem
  • 77
  • 7
5
votes
4 answers

SELECT DISTINCT for data groups

I have following table: ID Data 1 A 2 A 2 B 3 A 3 B 4 C 5 D 6 A 6 B etc. In other words, I have groups of data per ID. You will notice that the data group (A, B) occurs multiple times. I want a query that can identify the…
littlegreen
  • 7,290
  • 9
  • 45
  • 51
5
votes
1 answer

SQL Server query to display all columns but with distinct values in one of the columns (not grouping anything)

I have a table with 106 columns. One of those columns is a "Type" column with 16 types. I want 16 rows, where the Type is distinct. So, row 1 has a type of "Construction", row 2 has a type of "Elevator PVT", etc. Using Navicat. From what I've…
Avi
  • 53
  • 7
1 2
3
42 43