Substitute DataFrame Row Names by Values in Vector in R Last Updated : 30 Sep, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss how to substitute dataframe row names by values in a vector in R programming language. Dataframe in use: We can substitute row names by using rownames() function Syntax: rownames(dataframe) <- vector where, dataframe is the input dataframevector is the new row values Example: R program to substitute the rownames of the dataframe R # create a dataframe with 6 rows and 2 columns data = data.frame(sub1=c(100, 89, 90, 78, 98, 93), sub2=c(89, 91, 97, 67, 100, 89)) # consider the vector vec = c(10, 20, 30, 40, 50, 60) # substitute the row names by values in a vector rownames(data) = vec # display dataframe print(data) Output: Example: R program to substitute the rownames of the dataframe R # create a dataframe with 6 rows and 2 columns data = data.frame(sub1=c(100, 89, 90, 78, 98, 93), sub2=c(89, 91, 97, 67, 100, 89)) # consider the vector vec = c("row1", "row2", "row3", "row4", "row5", "row6") # substitute the row names by values in a vector rownames(data) = vec # display dataframe print(data) Output: We can also replace the row names by values in a dataframe Syntax: rownames(dataframe) <- dataframe$column_name where dataframe is the input dataframecolumn_name is the column of the dataframe Example: R program to substitute rownames of the dataframe using column R # create a dataframe with 6 rows and 2 columns data = data.frame(sub1=c(100, 89, 90, 78, 98, 93), sub2=c(89, 91, 97, 67, 100, 79)) # substitute the row names by sub1 column rownames(data) = data$sub1 # display dataframe print(data) # substitute the row names by sub2 column rownames(data) = data$sub2 # display dataframe print(data) Output: Comment More infoAdvertise with us Next Article Substitute DataFrame Row Names by Values in Vector in R S sravankumar_171fa07058 Follow Improve Article Tags : R Language R Programs R-DataFrame R DataFrame-Programs Similar Reads Subset DataFrame and Matrix by Row Names in R In this article, we are going to see how to evaluate subset dataframe and matrices by row name. Method 1: Subset dataframe by row names The rownames(df) method in R is used to set the names for rows of the data frame. A vector of the required row names is specified. The %in% operator in R is used t 2 min read Select rows from a DataFrame based on values in a vector in R In this article, we will discuss how to select rows from a DataFrame based on values in a vector in R Programming Language. Method 1: Using %in% operator %in% operator in R, is used to identify if an element belongs to a vector or Dataframe. It is used to perform a selection of the elements satisfyi 5 min read Merge DataFrames by Row Names in R In this article, we are going to see how to merge Dataframe by Row Name using merge in R Programming Language. The merge() function in base R can be used to merge input dataframes by common columns or row names. The merge() function retains all the row names of the dataframes, behaving similarly to 2 min read Convert Named Vector to DataFrame in R In this article, we will see how to convert the named vector to Dataframe in the R Programming Language. Method 1: Generally while converting a named vector to a dataframe we may face a problem. That is, names of vectors may get converted into row names, and data may be converted into a single colu 1 min read How to Retrieve Row Numbers in R DataFrame? In this article, we will discuss how to Retrieve Row Numbers in R Programming Language. The dataframe column can be referenced using the $ symbol, which finds its usage as data-frame$col-name. The which() method is then used to retrieve the row number corresponding to the true condition of the speci 2 min read Like