rank

Efficient assignment of percentile/rank in MYSQL

久未见 提交于 2019-12-22 10:12:23
问题 I have a couple of very large tables (over 400,000 rows) that look like the following: +---------+--------+---------------+ | ID | M1 | M1_Percentile | +---------+--------+---------------+ | 3684514 | 3.2997 | NULL | | 3684515 | 3.0476 | NULL | | 3684516 | 2.6499 | NULL | | 3684517 | 0.3585 | NULL | | 3684518 | 1.6919 | NULL | | 3684519 | 2.8515 | NULL | | 3684520 | 4.0728 | NULL | | 3684521 | 4.0224 | NULL | | 3684522 | 5.8207 | NULL | | 3684523 | 6.8291 | NULL | +---------+--------+--------

Calculate the rank of each index in a vector

微笑、不失礼 提交于 2019-12-22 09:24:17
问题 I'd like to calculate the rank of each index within a vector, e.g: x <- c(0.82324952352792, 0.11953364405781, 0.588659686036408, 0.41683742380701, 0.11452184105292, 0.438547774450853, 0.586471405345947, 0.943002870306373, 0.28184655145742, 0.722095313714817) calcRank <- function(x){ sorted <- x[order(x)] ranks <- sapply(x, function(x) which(sorted==x)) return(ranks) } calcRank(x) > calcRank(x) [1] 9 2 7 4 1 5 6 10 3 8 Is there a better way to do this? 回答1: Why not just: rank(x) # ..... ? # [1

Exclude null values using DENSE_RANK

你离开我真会死。 提交于 2019-12-22 07:05:54
问题 Dense_Rank is taking everything into account. Is there a way to exclude the null values so the next rank after 1 would be 2 and not 3. This is what the table looks like now: A | DENSE_R -------------- 1 | 1 -------------- 2 | null -------------- 3 | 3 -------------- 4 | 4 This is what I want the table to look like: A | DENSE_R -------------- 1 | 1 -------------- 2 | null -------------- 3 | 2 -------------- 4 | 3 I'm using the following code to do so:- WITH CTE AS ( SELECT A FROM A1 ) SELECT A

Sorting and ranking a dataframe by date and time in r

六月ゝ 毕业季﹏ 提交于 2019-12-19 07:47:49
问题 I have a dataframe as below. Originally it was just two columns/variables -"Timestamp" (which contains date and time) and "Actor". I broke down the "Timestamp" variable into "date" and "time" and then "time further down into "hours" and "mins". This then gives the following structure dataf<-structure(list(hours = structure(c(3L, 4L, 4L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 6L, 2L, 2L, 2L, 2L, 5L, 5L, 5L, 1L, 1L, 2L, 2L), .Label = c("9", "12", "14", "15", "16", "17"), class = "factor"), mins =

How to get a row rank?

大城市里の小女人 提交于 2019-12-19 02:38:09
问题 HI, I actually posted similar (or same?) question yesterday, but I thought I need to post a new question since I have short, but clear question. I have the following table. id point 1 30 2 30 3 29 4 27 5 28 6 26 what I want: get all the users order by rank. user #1 and #2 should have 1 as their rank value because they both have 30 points I want to query a rank by user id. I like to get 1 as the result of my rank when I query user #1 and #2 because both of them have 30 points Added on: 3/18 I

Set array's rank at runtime

眉间皱痕 提交于 2019-12-17 19:57:26
问题 I have written a program which reads a file containing multidimensional data (most commonly 3D, but 2D could occur as well). To heighten simplicity I would like to store the data in an array of the same rank (or something pretending to be one), i.e. using a three-dimensional array for 3D data, etc.; the trouble is that the program only learns about the dimensionality on reading the data file. Currently I store all data in an array of rank one and calculate each element's index in that array

Hive getting top n records in group by query

只谈情不闲聊 提交于 2019-12-17 17:32:11
问题 I have following table in hive user-id, user-name, user-address,clicks,impressions,page-id,page-name I need to find out top 5 users[user-id,user-name,user-address] by clicks for each page [page-id,page-name] I understand that we need to first group by [page-id,page-name] and within each group I want to orderby [clicks,impressions] desc and then emit only top 5 users[user-id, user-name, user-address] for each page but I am finding it difficult to construct the query. How can we do this using

How do I Handle Ties When Ranking Results in MySQL?

对着背影说爱祢 提交于 2019-12-17 16:38:08
问题 How does one handle ties when ranking results in a mysql query? I've simplified the table names and columns in this example, but it should illustrate my problem: SET @rank=0; SELECT student_names.students, @rank := @rank +1 AS rank, scores.grades FROM student_names LEFT JOIN scores ON student_names.students = scores.students ORDER BY scores.grades DESC So imagine the the above query produces: Students Rank Grades ======================= Al 1 90 Amy 2 90 George 3 78 Bob 4 73 Mary 5 NULL

rank in php based on average values

徘徊边缘 提交于 2019-12-14 00:03:37
问题 I've been trying for a while but still, I'm stuck here. Actually I need to get rank from average values. Here my result Average Rank 39 39 rank is 1 32 32 rank is 1 51 51 rank is 1 57 57 rank is 1 what I really need is Average Rank 39 3 32 4 51 2 57 1 I've tried several method, but nothing seem to be works. Btw Here's my code <?php $avg = ($sumc)/($data['total']); echo number_format((float)$avg, 2, ',', ''); ?> <?php $array = array($avg); $i=1; foreach($array as $key=>$value) { $max = max(

Mysql Query for Rank (RowNumber) and Groupings

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 08:02:02
问题 i have the similar problem mentioned in this thead but it's in SQL server and Mysql doesn't support "Partition By" as i know now what can i do? Here is the Question: I have a table that has some columns: User, Category, Value And I want to make a query that will give me a ranking, of all the users by the value, but reset for the category. Example: user1 CategoryA 10 user2 CategoryA 11 user3 CategoryA 9 user4 CategoryB 3 user1 CategoryB 11 the query would return: Rank User Category 1 user2