rank

How to partition when ranking on a particular column?

こ雲淡風輕ζ 提交于 2019-11-30 03:59:42
All: I have a data frame like the follow.I know I can do a global rank order like this: dt <- data.frame( ID = c('A1','A2','A4','A2','A1','A4','A3','A2','A1','A3'), Value = c(4,3,1,3,4,6,6,1,8,4) ); > dt ID Value 1 A1 4 2 A2 3 3 A4 1 4 A2 3 5 A1 4 6 A4 6 7 A3 6 8 A2 1 9 A1 8 10 A3 4 dt$Order <- rank(dt$Value,ties.method= "first") > dt ID Value Order 1 A1 4 5 2 A2 3 3 3 A4 1 1 4 A2 3 4 5 A1 4 6 6 A4 6 8 7 A3 6 9 8 A2 1 2 9 A1 8 10 10 A3 4 7 But how can I set a rank order for a particular ID instead of a global rank order. How can I get this done? In T-SQL, we can get this done as the following

Overloaded fortran interface with different ranks

北战南征 提交于 2019-11-29 23:15:50
问题 In a Fortran module I have a function that takes an array and its name, gets from a database (actually calling a C function) the shape of the array, copies the array in a temporary buffer and passes the buffer to another C function that processes it. This Fortran function has the name fs_WriteData_i for integer data, fs_WriteData_f for real and fs_WriteData_d for double precision. All these functions accept not only one-dimensional arrays, but also 2D, 3D and 4D arrays and they work perfectly

Pandas rank by multiple columns

痴心易碎 提交于 2019-11-29 20:52:12
问题 I am trying to rank a pandas data frame based on two columns. I can rank it based on one column, but how can to rank it based on two columns? 'SaleCount', then 'TotalRevenue'? import pandas as pd df = pd.DataFrame({'TotalRevenue':[300,9000,1000,750,500,2000,0,600,50,500], 'Date':['2016-12-02' for i in range(10)], 'SaleCount':[10,100,30,35,20,100,0,30,2,20], 'shops':['S3','S2','S1','S5','S4','S8','S6','S7','S9','S10']}) df['Rank'] = df.SaleCount.rank(method='dense',ascending = False).astype

rank data over a rolling window in pandas DataFrame

狂风中的少年 提交于 2019-11-29 14:17:20
I am new to Python and the Pandas library, so apologies if this is a trivial question. I am trying to rank a Timeseries over a rolling window of N days. I know there is a rank function but this function ranks the data over the entire timeseries. I don't seem to be able to find a rolling rank function. Here is an example of what I am trying to do: A 01-01-2013 100 02-01-2013 85 03-01-2013 110 04-01-2013 60 05-01-2013 20 06-01-2013 40 If I wanted to rank the data over a rolling window of 3 days, the answer should be: Ranked_A 01-01-2013 NaN 02-01-2013 Nan 03-01-2013 1 04-01-2013 3 05-01-2013 3

PowerPivot DAX - Dynamic Ranking Per Group (Min Per Group)

戏子无情 提交于 2019-11-29 14:06:55
I am searching for a method to utilize within Microsoft PowerPivot 2010 that will allow me to perform dynamic ranking that will automatically update the associated rank value based on filters and slicer values that are applied. Thusfar, all examples I have seen utilize the Calculate() DAX function that overrides existing filters within the PowerPivot table via the All() function which causes predefined filters that users may apply to be disregarded. To illustrate my requirements, please reference the example below: (Source Data within PowerPivot Window:) ---------------------------------------

Fortran: Choosing the rank of an allocatable array

我的梦境 提交于 2019-11-29 12:45:22
I am trying to write a program where I want the allocatable array A to be of either rank 1, 2, or 3, depending on my input at run-time. I want to do this since the subsequent operations on A are similar, and I have defined in a module an interface work with module procedures that when acted on A , gives the desired result. What I am doing currently is this: program main implicit none integer :: rank,n=10 real*8, allocatable :: A1(:) real*8, allocatable :: A2(:,:) read (*,*) rank if (rank.eq.1) then allocate (A1(n)) else if (rank.eq.2) then allocate (A2(n,n)) end if ! operate on the array if

How do I preserve continuous (1,2,3,…n) ranking notation when ranking in R?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 12:12:53
If I want to rank a set of numbers using the minimum rank for shared cases (aka ties): dat <- c(13,13,14,15,15,15,15,15,15,16,17,22,45,46,112) rank(dat, ties = 'min') I get the results: 1 1 3 4 4 4 4 4 4 10 11 12 13 14 15 However, I want the rank to be a continuous series consisting of 1,2,3,... n , where n is the number of unique ranks . Is there a way to make rank (or a similar function) rank a series of numbers by assigning ties to the lowest rank as above but instead of skipping subsequent rank values by the number of previous ties to instead continue ranking from the previous rank ? For

Ranking by Group in MySQL

江枫思渺然 提交于 2019-11-29 05:17:58
I have a table with one column as follows: name ------- Michael Michael Michael Michael John John John Alex Alex I need to rank them to give: name | rank --------|------ Michael |1 Michael |2 Michael |3 Michael |4 John |1 John |2 John |3 Alex |1 Alex |2 How can I perform that? There's nothing in mysql that lets you do this directly, but you can hack it in: SET @prev := null; SET @cnt := 1; SELECT name, IF(@prev <> name, @cnt := 1, @cnt := @cnt + 1) AS rank, @prev := name FROM yourtable ORDER BY name This sort of thing is easier done in your client app, using the same basic logic. Simple,

Rank per row over multiple columns in R

被刻印的时光 ゝ 提交于 2019-11-29 04:28:00
I'm using R for the analysis of my masterthesis. Unfortunately, I got stuck with this problem: I would like to compute a new variable which calculates the rank of one variable per row within many variables. Example: V1 V2 V3 NewVariable_V1 NewVariable_V2 NewVariable_V3 11 21 35 3 2 1 22 12 66 2 3 1 44 22 12 1 2 3 Does anyone know how to do that? I'd be glad for help. You're looking for rank. To get decreasing order, first negate the data.frame. data.frame(d, t(apply(-d, 1, rank, ties.method='min'))) # V1 V2 V3 V1.1 V2.1 V3.1 # 1 11 21 35 3 2 1 # 2 22 12 66 2 3 1 # 3 44 22 12 1 2 3 ?rank and

How to rank within groups in R?

◇◆丶佛笑我妖孽 提交于 2019-11-29 03:45:33
OK, check out this data frame... customer_name order_dates order_values 1 John 2010-11-01 15 2 Bob 2008-03-25 12 3 Alex 2009-11-15 5 4 John 2012-08-06 15 5 John 2015-05-07 20 Lets say I want to add an order variable that Ranks the highest order value, by name, by max order date, using the last order date at the tie breaker. So, ultimately the data should look like this: customer_name order_dates order_values ranked_order_values_by_max_value_date 1 John 2010-11-01 15 3 2 Bob 2008-03-25 12 1 3 Alex 2009-11-15 5 1 4 John 2012-08-06 15 2 5 John 2015-05-07 20 1 Where everyone's single order gets 1,