Replace the Elements of a Vector in R Programming - replace() Function Last Updated : 01 Jun, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 function # Initializing a string vector x <- c("GFG", "gfg", "Geeks") # Getting the strings x # Calling replace() function to replace # the word gfg at index 2 with the # GeeksforGeeks element y <- replace(x, 2, "GeeksforGeeks") # Getting the new replaced strings y Output : [1] "GFG" "gfg" "Geeks" [1] "GFG" "GeeksforGeeks" "Geeks" Example 2: Python3 # R program to illustrate # replace function # Initializing a string vector x <- c("GFG", "gfg", "Geeks") # Getting the strings x # Calling replace() function to replace # the word GFG at index 1 and Geeks at # index 3 with the A and B elements # respectively y <- replace(x, c(1, 3), c("A", "B")) # Getting the new replaced strings y Output: [1] "GFG" "gfg" "Geeks" [1] "A" "gfg" "B" Comment More infoAdvertise with us Next Article Replace the Elements of a Vector in R Programming - replace() Function K Kanchan_Ray Follow Improve Article Tags : R Language R Vector-Function Similar Reads Replace values of a Factor in R Programming - recode_factor() Function 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. Synta 1 min read Calculate Rank of the Values of a Vector in R Programming - rank() Function rank() function in R Language is used to return the sample ranks of the values of a vector. Equal values and missing values are handled in multiple ways. Syntax: rank(x, na.last) Parameters: x: numeric, complex, character, and logical vector na.last: Boolean Value to remove NAs Example 1: Python3 1= 1 min read Get or Set the Structure of a Vector in R Programming - structure() Function structure() function in R Language is used to get or set the structure of a vector by changing its dimensions. Syntax: structure(vec, dim) Parameters: vec: Vector dim: New Dimensions Example 1: Python3 1== # R program to get # the structure of a Vector # Creating a Vector # of Numbers x1 <- c(1:1 1 min read Convert an Object into a Vector in R Programming - as.vector() Function as.vector() function in R Language is used to convert an object into a vector. Syntax: as.vector(x) Parameters: x: Object to be converted Example 1: Python3 1== # R program to convert an object to vector # Creating an array x <- array(c(2, 3, 4, 7, 2, 5), c(3, 2)) x # Calling as.vector() Function 1 min read Replace all the matches of a Pattern from a String in R Programming - gsub() Function gsub() function in R Language is used to replace all the matches of a pattern from a string. If the pattern is not found the string will be returned as it is. Syntax: gsub(pattern, replacement, string, ignore.case=TRUE/FALSE) Parameters: pattern: string to be matched replacement: string for replacem 1 min read Like