Select DataFrame Column Using Character Vector in R Last Updated : 23 Sep, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to select dataframe columns using character vectors in R programming language. Data frame in use: To extract columns using character we have to use colnames() function and the index of the column to select is given with it using []. The approach is sort of the same as extracting a column from dataframe except instead of $, [] is used. Syntax: dataframe[ , colnames(dataframe)[column_number]] Here, dataframe is the input dataframecolnames function gives the column namescolumn number is a vector that takes column number with an index Example: R program to select dataframe columns using character vector R # create a dataframe with 3 columns and 4 rows data=data.frame(id=c(1,2,3,4), name=c('manoj','deepu','ramya','manoja'), marks=c(100,89,90,81)) # display column1 print(data[ , colnames(data)[1]] ) # display column2 print(data[ , colnames(data)[2]] ) # display column3 print(data[ , colnames(data)[3]] ) Output: [1] 1 2 3 4 [1] "manoj"  "deepu"  "ramya"  "manoja" [1] 100  89  90  81 Example 2:R program to select dataframe columns using character vector R # create a dataframe with 4 columns and 5 rows data=data.frame(id=c(1,2,3,4,5), name=c('manoj','deepu','ramya','manoja','sravya'), marks=c(100,89,90,81,90), address=c('hyd','pune','chennai','banglore','chennai')) # display column1 print(data[ , colnames(data)[1]] ) # display column2 print(data[ , colnames(data)[2]] ) # display column3 print(data[ , colnames(data)[3]] ) # display column4 print(data[ , colnames(data)[4]] ) Output: [1] 1 2 3 4 5 [1] "manoj"  "deepu"  "ramya"  "manoja" "sravya" [1] 100  89  90  81  90 [1] "hyd"    "pune"   "chennai"  "banglore" "chennai" Comment More infoAdvertise with us Next Article Select DataFrame Column Using Character Vector in R M manojkumarreddymallidi Follow Improve Article Tags : R Language R Programs R-DataFrame R DataFrame-Programs Similar Reads Concatenate Vector of Character Strings in R In this article, we will discuss how to concatenate the strings present in two or more vectors in R Programming Language. Discussed below are various methods of doing so. Method 1: Using paste() paste() function is used to combine strings present in vectors passed to it  an argument. Syntax: paste( 4 min read How to Select Specific Columns in R dataframe? In this article, we will discuss how to select specific columns from a data frame in the R Programming Language. Selecting specific Columns Using Base R by column nameIn this approach to select a specific column, the user needs to write the name of the column name in the square bracket with the name 7 min read Select DataFrame Rows where Column Values are in Range in R In this article, we will discuss how to select dataframe rows where column values are in a range in R programming language. Data frame indexing can be used to extract rows or columns from the dataframe. The condition can be applied to the specific columns of the dataframe and combined using the logi 2 min read How to Select DataFrame Columns by Index in R? In this article, we will discuss how to select columns by index from a dataframe in R programming language. Note: The indexing of the columns in the R programming language always starts from 1. Method 1: Select Specific Columns By Index with Base R Here, we are going to select columns by using index 2 min read Convert dataframe rows and columns to vector in R In this article, we are going to convert a dataframe column to a vector and a dataframe row to a vector in the R Programming Language. Convert dataframe columns into vectors We are taking a column in the data frame and passing it into another variable by using the selection method. The selection met 2 min read Like