Modified crayola solution but using match
instead of merge
:
x_unique <- unique(x)
x_ranks <- rank(x_unique)
x_ranks[match(x,x_unique)]
edit
or in a one-liner, as per @hadley ‘s comment:
match(x, sort(unique(x)))
More Related Contents:
- Several questions on ggplot2 [closed]
- Error in if/while (condition) {: missing Value where TRUE/FALSE needed
- Interpreting “condition has length > 1” warning from `if` function
- How to change legend title in ggplot
- Explicitly calling return in a function or not
- Importing Excel files into R, xlsx or xls
- Removing empty rows of a data file in R
- data.table – select first n rows within group [duplicate]
- Converting latitude and longitude points to UTM
- Read Excel file from a URL using the readxl package
- Solution. How to install_github when there is a proxy
- Convert a dataframe to presence absence matrix
- Convert *some* column classes in data.table
- Is it possible to rotate a plot in R (base graphics)?
- Split/subset a data frame by factors in one column [duplicate]
- plot.new has not been called yet
- Inputting NA where there are missing values when scraping with rvest
- Convert integer to words
- Count number of columns by a condition (>) for each row
- How to draw the boxplot with significant level?
- Stacked bar chart in R (ggplot2) with y axis and bars as percentage of counts
- How to make variable bar widths in ggplot2 not overlap or gap
- R: Select values from data table in range
- How to upgrade R in linux?
- How to group by two columns in R
- Stop lapply from printing to console
- R how can I calculate difference between rows in a data frame
- Preserve proportion of graphs using grid.arrange
- Knit one markdown file to two output files
- Display HTML file in Shiny App