find-occurrences

Counting records belonging to a category in MySQL

China☆狼群 提交于 2019-12-11 08:56:16
问题 I've been battling with some SQL and can't seem to get my head around it. I have two tables, one with the list of categories and another with all my articles. What i'm trying to do is find how many articles are present for each category. Here is the SQL I have so far SELECT DISTINCT COUNT( po.post_Cat_ID ) AS Occurances, ca.cat_Title FROM Posts po, Categories ca WHERE ca.cat_ID = LEFT( po.post_Cat_ID, 2 ) The reason I use LEFT is to only get the main categories as I have listed categories as

find the number of occurences and add it next to the pattern

只愿长相守 提交于 2019-12-11 04:59:26
问题 I have several files in a directory and in some of them, some patterns occur multiple times. For example Contents of file " 8_list ": Spiroplasma_taiwanense Spiroplasma_diminutum Spiroplasma_apis Spiroplasma_sabaudiense Spiroplasma_taiwanense Spiroplasma_diminutum Spiroplasma_taiwanense EntAcro10 EntAcro10 Spiroplasma_apis Spiroplasma_culicicola Spiroplasma_sabaudiense Spiroplasma_diminutum Spiroplasma_sabaudiense Spiroplasma_sabaudiense Spiroplasma_sabaudiense Spiroplasma_apis Spiroplasma

Counting number of occurances in an Array

橙三吉。 提交于 2019-12-11 00:37:47
问题 I want to count number of occurances in an array in ActionScript 3.0. Say I have var item:Array = ["apples", "oranges", "grapes", "oranges", "apples", "grapes"]; How can I make it show the number of matching strings? For instance, result: apples = 2, oranges = 2 etc. I got this code from another similar question: private function getCount(fruitArray:Array, fruitName:String):int { var count:int=0; for (var i:int=0; i<fruitArray.length; i++) { if(fruitArray[i].toLowerCase()==fruitName

Count occurrences of elements inside array? (Java)

情到浓时终转凉″ 提交于 2019-12-10 10:34:16
问题 I have been working on trying to figure out this algorithm for about 6 hours now and can't seem to come up with a solution. I am trying to count the occurrences of elements inside an array and may two more separate arrays. One for the unique instances, and one for how many times these instances occurs. I found some other thinks on here about array lists and hashMaps, but I am only able to use arrays. For example, I have this array (already sorted): {cats, cats, cats, dog, dog, fish} I am

Find the position of the first occurrence of any number in string

▼魔方 西西 提交于 2019-12-09 02:57:48
问题 Can someone help me with algorithm for finding the position of the first occurrence of any number in a string? The code I found on the web does not work: function my_offset($text){ preg_match('/^[^\-]*-\D*/', $text, $m); return strlen($m[0]); } echo my_offset('[HorribleSubs] Bleach - 311 [720p].mkv'); 回答1: function my_ofset($text){ preg_match('/^\D*(?=\d)/', $text, $m); return isset($m[0]) ? strlen($m[0]) : false; } should work for this. The original code required a - to come before the first

Count occurrences of elements inside array? (Java)

筅森魡賤 提交于 2019-12-06 13:35:18
I have been working on trying to figure out this algorithm for about 6 hours now and can't seem to come up with a solution. I am trying to count the occurrences of elements inside an array and may two more separate arrays. One for the unique instances, and one for how many times these instances occurs. I found some other thinks on here about array lists and hashMaps, but I am only able to use arrays. For example, I have this array (already sorted): {cats, cats, cats, dog, dog, fish} I am trying to get make an array for the instances, so: {cats, dog, fish} And finally, how many times these

R How to count occurrences of values across multiple columns of a data frame and save the columnwise counts from a particular value as a new row?

China☆狼群 提交于 2019-12-06 10:59:53
I have a large data-frame (approx 1,000 rows and 30,000 columns) that looks like this: chr pos sample1 sample2 sample3 sample 4 1 5050 1 NA 0 0.5 1 6300 1 0 0.5 1 1 7825 1 0 0.5 1 1 8200 0.5 0.5 0 1 where at a given "chr"&"pos" the value for a given sample can take the form of 0, 0.5, 1, or NA. I have a large number of queries to perform that will require subsetting and ordering the data frame based on summaries of the values for each sample. I would like to get a count of the number of occurrences of a given value (e.g. 0.5) for each column, and save that as a new row in my data frame. My

Python co-occurrence of two items in different lists

血红的双手。 提交于 2019-12-06 07:59:42
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 be like: { ['cat', 'fish']: 3, ['cat', 'dog']: 1,['cat','bird']:1 ['fish','dog'] : 1, ['fish','bird']:2} I tried : from collections import Counter from collections import defaultdict co_occurences = defaultdict(Counter) for tags in names: for key in tags: co_occurences[key].update(tags) print co_occurences but it doesn't count co=occurrences in the

How to fix segmentation fault 11 error? [duplicate]

无人久伴 提交于 2019-12-04 21:40:36
This question already has an answer here : Definitive List of Common Reasons for Segmentation Faults (1 answer) Closed 2 years ago . I want the main returns the position of the occurrences of "mdl" in "dati". I set up the "schema" function to find the starting point of each occurrence, but when i run the program from the command line, it returns: Segmentation fault: 11 I don't know how to fix the problem. Here's the code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int schema(int testo[], int nT, int modello[], int nM, int primo) { int i, j, k; static int r[12]

Show count of occurrences when smart highlighting in Notepad++

风格不统一 提交于 2019-12-04 16:13:07
问题 Is it possible to show the number of occurrences of words which are smart highlighted? I mean when you double click on a word. In Matlab e.g. smart highlighting is activated by having the cursor touching a word and in the tool bar it instantly says for instance 4 usages of "weight" found . Doing a search for the word/phrase will give you the same information, but how about having the count directly be shown somewhere? BTW: Can smart highlighting be activated in a different manner than double