Questions tagged [find-occurrences]

435 questions
3
votes
5 answers

Python co-occurrence of two items in different lists

I have a list of lists like : names = [['cat', 'fish'], ['cat'], ['fish', 'dog', 'cat'], ['cat', 'bird', 'fish'], ['fish', 'bird']] I want to count number of times that each pair of names mentioned together in the whole list and the output would…
mk_sch
  • 1,060
  • 4
  • 16
  • 31
3
votes
0 answers

Ruby: How to find the most frequent substring of length n?

I'm trying to figure out if there is a shorter more ruby-like way of finding the most frequent substring of length n? I wrote the following code: def most_frequent_kmers(length) dna = text.each_char.to_a array_dna_substrings =…
Al V
  • 1,227
  • 2
  • 11
  • 15
3
votes
4 answers

Removing lines with the first and the last occurence of a column value

I have following file ID Score Other ABR 0.98 NBNMSB BCG 0.76 NBNMSB CVD 0.6 NBNMSB BCG 0.9 VSCVA CVD 0.56 VSCVA ABR 0.9 VSCVA CVD 0.7 BAVSC BCG …
AishwaryaKulkarni
  • 774
  • 1
  • 8
  • 19
3
votes
3 answers

Count patterns and differentiate them

I'd like to count a defined pattern (here: 'Y') in a string for each row of a dataframe. Ideally, I'd like to get a number of occurrences in V3 and length in V4. Input: V1 V2 A XXYYYYY B XXYYXX C XYXXYX D XYYXYX Output: V1 V2 V3 …
user2904120
  • 416
  • 1
  • 4
  • 18
3
votes
4 answers

Accessing a repeated element in the list and printing the element next to it

I have this function, which takes 3 arguments. 1) a list containing strings, 2) search_term and 3) place (optional argument). Code: def ls_src(list,search_term,place=1): if search_term in list: a = list[list.index(search_term)+1]+':' +…
Parthvi Vala
  • 73
  • 2
  • 6
3
votes
1 answer

Count number of occurence to an index of a vector

I am currently working on optimization of a R code. So, I try to avoid dynamic memory allocation, FOR loop, ... But, I have some difficulties with some FOR loop, I need to create a behaviour like this : INPUT : v <-…
3
votes
4 answers

Tagging phrases in paragragh

I am using PHP and I am looking to create links within my text to other sections of the site so for example: I fell into the media industry aged 30, when David Mansfield, now on the board of Ingenious Media, gave me my first break at Thames TV. From…
Lizard
  • 43,732
  • 39
  • 106
  • 167
3
votes
2 answers

Finding multiple occurrences of pairs in CSV file

I'm trying to write a Python script that will search through a CSV file and identify the number of occurrences when two items appear next to each other. For example, let's say the CSV looks like the…
AdjunctProfessorFalcon
  • 1,790
  • 6
  • 26
  • 62
3
votes
6 answers

Java count occurrence of each item in an sorted array

I have an Array of Strings and want to count the occurrences of any single String. I have already sorted it. (It's a long Array and I wanted to get rid of the O(n²)-loop) Here my code.. obviously it runs out in an ind.outOfB. exc.. the reason is…
Jan S
  • 117
  • 3
  • 14
3
votes
4 answers

Javascript - Regex : How to replace id in string with the same id plus number?

I have a string with multiple elements with id's like below: var data = "
"; Now I'm using this regex to find all the id's in the string: var reg = /id="([^"]+)"/g; Afterwards I want to replace all those…
Phillip-juan
  • 546
  • 4
  • 29
3
votes
2 answers

Solving unusual "out of range" error behavior

I'm creating C# winforms app which has to find all occurences of a string within a file, crop the text in between, then do some processing. The text file has following format: ---- Key_String ---- text to crop 1 ---- Key_String ---- text to…
Alex
  • 4,607
  • 9
  • 61
  • 99
3
votes
5 answers

How can I find the number that occurs most number of times using JavaScript?

If a user enters 5 numbers, lets say... 4, 4, 7, 7, 4. 4 occurred 3 (most number of) times. So the output should be 4. How can I do this using JavaScript? Would much appreciate your help. Thanks! I've tried this so far. It works, but it's too long,…
Sai Kiran Sripada
  • 1,149
  • 3
  • 15
  • 30
2
votes
1 answer

RegExp only - check if text contains specified character within provided range of occurrences

I would like to check if f.e letter "a" occurs between 3 and 5 times (inclusive), in total, within provided text input. Given: zayaaxaawv <- 5 of "a", passed zayaxawva <- 4 of "a", passed zaaay <- 3 of "a", passed zayax <- 2 of "a",…
ScriptyChris
  • 639
  • 4
  • 16
  • 48
2
votes
3 answers

How to extract last occurrence of a particular 'string' from a vector

I have a vector of several binary numbers stored in it. Since these are already filtered, it is also known that all are greater than 0. v <- c(1, 10, 11, 110, 10000, 101000, 100100000, 100001) Now I want a result_vector (vector because input…
AnilGoyal
  • 25,297
  • 4
  • 27
  • 45
2
votes
2 answers

Cumulative count of occurence on date PowerBI?

dataset resembles this: ID Milestone id1 01/01/2020 id2 02/01/2020 id3 04/01/2020 id4 null id5 02/01/2020 id6 12/01/2020 I'm trying to count the number of records have reached the milestone…
1 2
3
28 29