Quoting directly from the help page for factor
:
To transform a factor f to its original numeric values, as.numeric(levels(f))[f]
is recommended and slightly more efficient than as.numeric(as.character(f))
.
More Related Contents:
- Check if the number is integer
- How to convert integer number into binary vector?
- Why would R use the “L” suffix to denote an integer?
- Converting two columns of a data frame to a named vector
- What is integer overflow in R and how can it happen?
- What’s the difference between integer class and numeric class in R
- Why does “one” < 2 equal FALSE in R?
- Clarification of L in R
- How to catch integer(0)?
- r – How to find value with condition
- Formula with dynamic number of variables
- Order a “mixed” vector (numbers with letters)
- Summarizing by subgroup percentage in R
- Define and apply custom bins on a dataframe
- How to perform join over date ranges using data.table?
- Creating grouped bar-plot of multi-column data in R
- detach all packages while working in R
- Assigning Dates to Fiscal Year
- Find the n most common values in a vector [duplicate]
- Case-insensitive search of a list in R
- Directly creating dummy variable set in a sparse matrix in R
- Error: package or namespace load failed for ‘tidyverse’ in loadNamespace
- Create frequency tables for multiple factor columns in R
- R function not returning values
- How to prevent scientific notation in R? [duplicate]
- Reason behind speed of fread in data.table package in R
- The perils of aligning plots in ggplot
- How to create a new variable in a data.frame based on a condition?
- how to plot ellipse given a general equation in R?
- What does the %% operator mean in R? [closed]