-1

My Dataframe is as follows:

The column ID is a sequence of 1-63 in repetition. I wish to add two new columns Closepctl and Quantitypctl in which I can rank each entry from 1-63 i.e., on the basis of Close and Quantity column but grouped with respect to ID. Is there any way to do this in R?

I tried it in excel but failed to find any grouping option there. Excel approach is also appreciated.

alistaire
  • 42,459
  • 4
  • 77
  • 117
kgsd
  • 11
  • 5
  • Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) when you're asking a question. – Adam Quek Apr 19 '17 at 03:23
  • 1
    And please provide data as plain text, not an image. – neilfws Apr 19 '17 at 03:25

1 Answers1

1

See if the following is helpful...

library(dplyr)
data(iris)    
df <- iris %>%
  group_by(Species) %>%
  mutate(RankSepal = percent_rank(Sepal.Length), 
         RankPetal = percent_rank(Petal.Length))
M.Qasim
  • 1,827
  • 4
  • 33
  • 58
  • `dplyr` also has the `percent_rank()` function, which may be what the OP was looking for (based on the title of the question). – eipi10 Apr 19 '17 at 03:33
  • The question is updated. If you don't mind, please try on this example. – kgsd Apr 19 '17 at 04:34