rank

Calculate the rank of each index in a vector

邮差的信 提交于 2019-12-06 03:00:54
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? Why not just: rank(x) # ..... ? # [1] 9 2 7 4 1 5 6 10 3 8 match is what you want: match(x, sort(x)) 来源: https://stackoverflow.com/questions

Why does order(order(x)) is equal to rank(x) in R?

眉间皱痕 提交于 2019-12-06 01:10:33
In this post it is stated that order(order(x)) is the same as rank(X) . While some experiments corroborate this... #why is order(order(x)) == rank(x)? x <- c(0.2, 0.5, 0.1) x ## [1] 0.2 0.5 0.1 order(x) ## [1] 3 1 2 rank(x) ## [1] 2 3 1 order(order(x)) ## [1] 2 3 1 I fail to see how this can be proved and, even better, intuited. Related: rank and order in R First off look at what happens with an integer sequence formed from a permutation of 1:10: > set.seed(123); x <- sample(10) > x [1] 3 8 4 7 6 1 10 9 2 5 > order(x) [1] 6 9 1 3 10 5 4 2 8 7 > order(order(x)) [1] 3 8 4 7 6 1 10 9 2 5 > rank(x

rank deficiency warning mixed model lmer

无人久伴 提交于 2019-12-05 02:55:57
问题 I have a dataset with 142 data entries: 121 individuals measured on two occasions (two years, before and after treatment, Year = 0 or 1), in the second year 46 individuals were in treated plots and the rest were in control plots (treatment = 0 or 1). Here's some example data: ID <- c("480", "480", "620", "620","712","712") Year <- c("0", "1", "0", "1","0", "1") Plot <- c("14", "14", "13", "13","20","20") Treat <- c("0", "0", "0", "1", "0", "1") Exp <- c("31", "43", "44", "36", "29", "71")

MySQL - ranking by count() and GROUP BY

混江龙づ霸主 提交于 2019-12-05 02:47:06
问题 I've got my mysql table posts , where all posts of my forum are stored. It's like this: id uid thread post title text time (int) (int) (varchar) (int) (varchar) (text) (int) Now I want to show the rank (ranking of number of posts) on the user profiles. I've tried something like this: set @rownum := 0; SELECT @rownum := @rownum + 1 AS rank, uid, count(id) FROM `posts` GROUP BY uid ORDER BY count(id) But it returns not the right data. The uid and count(id) match, but the rank is wrong. My entry

Get a rank, based on score, from an unordered MySql Database when given a Username

假如想象 提交于 2019-12-05 01:34:25
问题 Okay so I have a table that has the following KEY username password score The above columns are not in any specific order. I want to send my Database a username and have it send me back what rank that user name is based on its score. So for example if I had 10 people in there and the 3rd person in has the highest score. When I pass the 3rd persons username in I want it to send back 1. Is this possible? I have been trying things like this $result = mysql_query("SELECT * FROM tablename where

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

How does R do exact wilcox rank sum tests?

和自甴很熟 提交于 2019-12-04 14:43:53
I read the documentation in R for wilcox.test() and want to determine: How R computes wilcox.test() The docs say that when the number of samples is small, it does the test exactly (instead of using a normal approximation) -- what tables does it use to do this exactly? wilcox.test.default is "hidden" in the stats package's namespace. That's why you need to do getAnywhere("wilcox.test.default") or stats:::wilcox.test.default to view it. Package exactRankTests can do exact wilcox rank sum tests. 来源: https://stackoverflow.com/questions/12395110/how-does-r-do-exact-wilcox-rank-sum-tests

SQL rank percentile

有些话、适合烂在心里 提交于 2019-12-04 06:54:19
问题 I've made an SQL query which rank pages by how many times they have been viewed. For instance, ╔══════╦═══════╗ ║ PAGE ║ VIEWS ║ ╠══════╬═══════╣ ║ J ║ 100 ║ ║ Q ║ 77 ║ ║ 3 ║ 55 ║ ║ A ║ 23 ║ ║ 2 ║ 6 ║ ╚══════╩═══════╝ Now what I would like to do is find the percentile rank of each page using an SQL query. The math I would like to use for this is simple enough, I just want to take the row number of the already generated table divided by the total number of rows. Or 1 minus this value,

How to calculate student rank in access

落花浮王杯 提交于 2019-12-04 05:25:02
问题 I want to calculate student rank based on their obtmarks as per below tables. Suppose any student scored highest marks in their class but he/she fail in any one subjects then they shouldn't consider for rank. 1. Table name is "resultdata" Total marks of full marks is(1000) pass marks is 33 ID | subject ID | subject | fullmarks | obtmarks |passmarks 1 | 1 | HINDI | 100 | 80 | 33 2 | 2 | ENGLISH | 100 | 90 | 33 3 | 3 | MATHEMATICS | 100 | 76 | 33 4 | 4 | SOCIAL SCIENCE| 100 | 69 | 33 like that

How to find column-index of top-n values within each row of huge dataframe

跟風遠走 提交于 2019-12-04 03:05:36
问题 I have a dataframe of format: (example data) Metric1 Metric2 Metric3 Metric4 Metric5 ID 1 0.5 0.3 0.2 0.8 0.7 2 0.1 0.8 0.5 0.2 0.4 3 0.3 0.1 0.7 0.4 0.2 4 0.9 0.4 0.8 0.5 0.2 where score range between [0,1] and I wish to generate a function that, for each id (row), calculates the top n metrics, where n is an input of the function along with the original dataframe. My ideal output would be:(for eg. n = 3) Top_1 Top_2 Top_3 ID 1 Metric4 Metric5 Metric1 2 Metric2 Metric3 Metric5 3 Metric3