Replace values of a Factor in R Programming - recode_factor() Function Last Updated : 01 Jun, 2020 Comments Improve Suggest changes Like Article Like Report Factors in R programming are kind of data structures that stores categorical data i.e., levels and can have any type of data (integer, string, etc). recode_factor() function in R Language is used to replace certain values in a factor. To use recode_factor() function, dplyr package is required. Syntax: recode_factor(x, ..., .ordered = TRUE) Parameters: x: represents factor object of a vector ... :represents replacements .ordered: creates an ordered factor if TRUE. Example 1: Python3 # Required for recode_factor() function install.packages("dplyr") # Loading package library(dplyr) # Create factor object f <- as.factor(c("a", "b", "c")) # Print factor object cat("Before replacement:\n") print(f) # Replacing single value cat("After replacement:\n") print(recode_factor(f, "a" = "x")) Output: Before replacement: [1] a b c Levels: a b c After replacement: [1] x b c Levels: x b c Example 2: Python3 # Required for recode_factor() function install.packages("dplyr") # Loading package library(dplyr) # Create factor object f <- as.factor(c("a", "b", "c")) # Print factor object cat("Before replacement:\n") print(f) # Replacing multiple values cat("After replacement:\n") print(recode_factor(f, "a" = "x", "b" = "y")) Output: Before replacement: [1] a b c Levels: a b c After replacement: [1] x y c Levels: x y c Comment More infoAdvertise with us Next Article Replace values of a Factor in R Programming - recode_factor() Function U utkarsh_kumar Follow Improve Article Tags : R Language R-Factors R Factor-Function Similar Reads Calculate Factorial of a value in R Programming - factorial() Function The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. It is defined as: n! = n à (n - 1) à (n - 2) à ... à 2 à 1For example 5! = 5 à 4 à 3 à 2 à 1 = 1200! is defined to be 1.Factorials have important applications in mathematics, co 3 min read Convert a Vector into Factor in R Programming - as.factor() Function as.factor() function in R Programming Language is used to convert the passed object(usually Vector) into a Factor. Syntax: as.factor(object) Parameters: Object: Vector to be convertedas.factor() Function in R ExampleExample 1: Convert a Factor in RR # Creating a vector x<-c("female", "male", "ma 1 min read Replace the Elements of a Vector in R Programming - replace() Function replace() function in R Language is used to replace the values in the specified string vector x with indices given in list by those given in values. Syntax: replace(x, list, values) Parameters: x: vector list: indices values: replacement values Example 1: Python3 # R program to illustrate # replace 1 min read Rename Columns of a Data Frame in R Programming - rename() Function The rename() function in R Programming Language is used to rename the column names of a data frame, based on the older names.Syntax: rename(x, names) Parameters:x: Data frame names: Old name and new name 1. Rename a Data Frame using rename function in RWe are using the plyr package to rename the col 2 min read Checking if the Object is a Factor in R Programming - is.factor() Function is.factor() function in R Language is used to check if the object passed to the function is a Factor or not. It returns a boolean value as output. Syntax: is.factor(Object) Parameters: Object: Object to be checked Example 1: Python3 1== # Creating a vector x<-c("female", "male 1 min read Like