ranking

Frequency count of 5 rankings in R

。_饼干妹妹 提交于 2019-12-06 06:53:21
Say I have 5 items A, B, C, D, E in a questionnaire and got respondents to rank them. The data looks like this, > df rank1 rank2 rank3 rank4 rank5 1 A B C D E 2 A C B D E 3 C A B E D 4 B A C D E 5 A B D C E How do I count the frequency of each rank by item so the output looks like this, item rank1 rank2 rank3 rank4 rank5 1 A 3 2 0 0 0 2 B 1 2 2 0 0 3 C 1 1 2 1 0 4 D 0 0 1 3 1 5 E 0 0 0 1 4 We can use table after converting to factor using base R lvls <- sort(unique(unlist(df))) sapply(df, function(x) table(factor(x, levels =lvls))) # rank1 rank2 rank3 rank4 rank5 #A 3 2 0 0 0 #B 1 2 2 0 0 #C 1

Ranking Elements of multiple Lists by their count in Python

本小妞迷上赌 提交于 2019-12-06 05:01:04
I want to rank multiple lists according to their elements how often they appear in each list. Example: list1 = 1,2,3,4 list2 = 4,5,6,7 list3 = 4,1,8,9 result = 4,1,2,3,4,5,6,7,8 (4 is counted three times, 1 two times and the rest once) I've tried the following but i need something more intelligent and something i can do with any ammount of lists. l = [] l.append([ 1, 2, 3, 4, 5]) l.append([ 1, 9, 3, 4, 5]) l.append([ 1, 10, 8, 4, 5]) l.append([ 1, 12, 13, 7, 5]) l.append([ 1, 14, 13, 13, 6]) x1 = set(l[0]) & set(l[1]) & set(l[2]) & set(l[3]) x2 = set(l[0]) & set(l[1]) & set(l[2]) & set(l[4])

How I can create a new ties.method with the R rank() function? [duplicate]

帅比萌擦擦* 提交于 2019-12-06 00:58:43
问题 This question already has answers here : How to get ranks with no gaps when there are ties among values? (8 answers) Closed 2 years ago . I'm trying to order this dataframe by population and date, so I'm using the order() and rank() functions: > df <- data.frame(idgeoville = c(5, 8, 4, 3, 4, 5, 8, 8), date = c(rep(1950, 4), rep(2000, 4)), population = c(500, 450, 350, 350, 650, 500, 500, 450)) > df idgeoville date population 1 5 1950 500 2 8 1950 450 3 4 1950 350 4 3 1950 350 5 4 2000 650 6 5

Join single row from a table in MySQL

蓝咒 提交于 2019-12-05 12:04:04
I have two tables players and scores . I want to generate a report that looks something like this: player first score points foo 2010-05-20 19 bar 2010-04-15 29 baz 2010-02-04 13 Right now, my query looks something like this: select p.name player, min(s.date) first_score, s.points points from players p join scores s on s.player_id = p.id group by p.name, s.points I need the s.points that is associated with the row that min(s.date) returns. Is that happening with this query? That is, how can I be certain I'm getting the correct s.points value for the joined row? Side note: I imagine this is

SQL ranking query to compute ranks and median in sub groups

时光毁灭记忆、已成空白 提交于 2019-12-05 03:03:52
I want to compute the Median of y in sub groups of this simple xy_table : x | y --groups--> gid | x | y --medians--> gid | x | y ------- ------------- ------------- 0.1 | 4 0.0 | 0.1 | 4 0.0 | 0.1 | 4 0.2 | 3 0.0 | 0.2 | 3 | | 0.7 | 5 1.0 | 0.7 | 5 1.0 | 0.7 | 5 1.5 | 1 2.0 | 1.5 | 1 | | 1.9 | 6 2.0 | 1.9 | 6 | | 2.1 | 5 2.0 | 2.1 | 5 2.0 | 2.1 | 5 2.7 | 1 3.0 | 2.7 | 1 3.0 | 2.7 | 1 In this example every x is unique and the table is already sorted by x . I now want to GROUP BY round(x) and get the tuple that holds the median of y in each group. I can already compute the median for the whole

Voting algorithm: how to calculate rank?

纵然是瞬间 提交于 2019-12-04 23:11:58
问题 I am trying to figure our a way to calculate rank. Right now it simply takes ratio of wins / losses of each individual entry, so e.g. one won 99 times out of a 100, it has 99% winning rank. BUT if an entry won 1 out of total 1 votes, it will have a 100% winning rank, but definitely it can't be higher that of the one that won 99 times. What would be a better way to do this? 回答1: Depending on how complicated you want to make it, the Elo system chess uses (or something similar) may be what you

Rank and unrank Combination with constraints

隐身守侯 提交于 2019-12-04 19:20:40
I want to rank and unrank combinations with an Element distance constraint. Selected elements cannot repeated. For example: n := 10 elements choose from k := 5 elements being choosen d := 3 max distance between 2 choosen elements 1,3,5,8,9 matches the constraint 1,5,6,7,8 dont matches the constraint How can ranking the combination with given distance constraint, where 1,2,3,4,5 is smaller than 1,2,3,4,6 ? Is there a way do the ranking without compute the combinations with smaller Rank? You can do this by first creating and populating a two-dimensional array, which I will call NVT for "number

Best way to use PostgreSQL full text search ranking

巧了我就是萌 提交于 2019-12-04 08:28:11
问题 Following on from this answer I want to know what the best way to use PostgreSQL's built-in full text search is if I want to sort by rank, and limit to only matching queries. Let's assume a very simple table. CREATE TABLE pictures ( id SERIAL PRIMARY KEY, title varchar(300), ... ) or whatever. Now I want to search the title field. First I create an index: CREATE INDEX pictures_title ON pictures USING gin(to_tsvector('english', title)); Now I want to search for 'small dog' . This works: SELECT

How I can create a new ties.method with the R rank() function? [duplicate]

混江龙づ霸主 提交于 2019-12-04 06:09:37
This question already has answers here : Closed 2 years ago . How to get ranks with no gaps when there are ties among values? (8 answers) I'm trying to order this dataframe by population and date, so I'm using the order() and rank() functions: > df <- data.frame(idgeoville = c(5, 8, 4, 3, 4, 5, 8, 8), date = c(rep(1950, 4), rep(2000, 4)), population = c(500, 450, 350, 350, 650, 500, 500, 450)) > df idgeoville date population 1 5 1950 500 2 8 1950 450 3 4 1950 350 4 3 1950 350 5 4 2000 650 6 5 2000 500 7 8 2000 500 8 8 2000 450 With ties.method = "first" I have no problem, finally I'm producing

Select N records for each category and order by X

扶醉桌前 提交于 2019-12-04 04:31:38
问题 I have a database table that contains blog posts. I want to show on the homepage one (or more) post for each category, ordering by date, for example. So my posts table looks like this: id | title | description | cat | filename | date How would I create such a query? I've thought to use group-by or a subselect but I'm not sure if it's a good thing for performance... the table has a large number of records. 回答1: MySQL doesn't support analytic functions (ROW_NUMBER, RANK, DENSE_RANK, NTILE...),