-1

i have a column say the first column below 'rawdata', i need to calculate rank, percentile and quintile in the below format using the rawdata column?

RawData Quintiles    Rank   Rank Percentile
    1.20    1    87     3
    0.58    2    897    30
    0.16    5    2,564  84
    1.04    1    145    5
    NA      na      
    0.32    4    1,966  64
    0.18    5    2,471  81
    0.22    4    2,374  78
    0.89    1    241    9
    0.46    3    1,362  45
Texan
  • 15
  • 5
  • Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Mar 24 '18 at 18:50

2 Answers2

0
RawData <- c(1.20, 0.16, 0.58, 1.04)

in general, you can combine the outputs of individual calculations of descriptive statistics into a data.frame using cbind

df <- cbind(
  RawData,
  quantile = quantile(RawData),
  rank = rank(RawData)
)

However, in the data you shared, there are more values of ranks than there are entries in the data set. Are you asking how you would calculate these specific values of rank, quantile, etc. given this particular raw values?

SubstantiaN
  • 373
  • 4
  • 14
  • Great! I'm glad it was helpful. Would you mind accepting it has an answer? It helps boost my reputation score in this community – SubstantiaN Mar 25 '18 at 22:10
0

Perhaps something like this (although it does not reproduce your figures, but presumably this is just part of a larger table)...

df <- data.frame(RawData = c(1.2, 0.58, 0.16, 1.04, NA, 1966, 2471, 2374, 241, 1362))

df$Quintile <- cut(df$RawData,quantile(df$RawData,seq(0,1,0.2),na.rm=TRUE),labels=1:5,include.lowest = TRUE)
df$Rank <- rank(df$RawData,na.last="keep")
df$Percentile <- 100*df$Rank/max(df$Rank,na.rm=TRUE)

df
   RawData Quintile Rank Percentile
1     1.20        2    4   44.44444
2     0.58        1    2   22.22222
3     0.16        1    1   11.11111
4     1.04        2    3   33.33333
5       NA     <NA>   NA         NA
6  1966.00        4    7   77.77778
7  2471.00        5    9  100.00000
8  2374.00        5    8   88.88889
9   241.00        3    5   55.55556
10 1362.00        4    6   66.66667
Andrew Gustar
  • 17,295
  • 1
  • 22
  • 32