Read CSV file and select specific rows and columns in R Last Updated : 20 May, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to see how to read CSV file and select specific rows and columns in R Programming Language. CSV file: To import a CSV file into the R environment we need to use a pre-defined function called read.csv(). Pass filename.csv as a parameter within quotations. First, we need to set the path to where the CSV file is located using setwd( ) otherwise we can pass the full path of the CSV file into read.csv( ) as a parameter. Example 1: Selecting specific multiple rows R df = read.csv('C:/Users/KRISHNA KARTHIKEYA/Documents/item.csv') a = df[c(2, 7),] print(a) Output : Explanation : In the first step, we have imported a CSV file into the R environment using read.csv( ) function.In the next step, we have selected 2,7 rows from CSV file using indexing and storing the result into a variable Example 2: Selecting specific single rows R df = read.csv('C:/Users/KRISHNA KARTHIKEYA/Documents/item.csv') a = df[ 2, ] print(a) Output : Example 3: Selecting multiple columns R df = read.csv('C:/Users/KRISHNA KARTHIKEYA/Documents/item.csv') a = df[, c(3 , 4)] print(a) Output : Comment More infoAdvertise with us Next Article Read text File with Space as Delimiter in R K krishnakarthikeyakhandrika Follow Improve Article Tags : R Language R-CSV Similar Reads How to read Excel file and select specific rows and columns in R? In this article, we will discuss how to read an Excel file and select specific rows and columns from it using R Programming Language. File Used: To read an Excel file into R we have to pass its path as an argument to read_excel() function readxl library. Syntax: read_excel(path) To select a specific 2 min read Choose Specific Columns of a Data Frame in R Programming - select() Function select() function in R Language is used to choose whether a column of the data frame is selected or not. Syntax: select(x, expr) Parameters: x: Data frame expr: condition for selection Example 1: Python3 1== # R program to select specific columns # Loading library library(dplyr) # Create a data fram 2 min read Import Only Selected Columns of Data from CSV in R In this article, we will be looking at two different approaches to import selected columns of the Data from a CSV file in the R programming language. Method 1: Using read.table() function In this method of only importing the selected columns of the CSV file data, the user needs to call the read.tabl 2 min read Read text File with Space as Delimiter in R In this article, we will discuss how to read a text file with spaces as delimiters in R programming language. Base R allows us to read and access the content within the text files with any number of characters as the delimiter. File in use: The read.table() method in R can be used to read data fro 2 min read Specify Row Names when Reading Excel File in R In this article, we are going to specify the row names when reading Excel file in the R Programming language. Specifying row names when reading a file using row.names argument of the read.xlsx2() function. This is the easiest approach to specify the row names when reading a file in the R programming 2 min read Select Subset of DataTable Columns in R In this article, we will discuss how to select a subset of data table columns in R programming language. Let's create a data table using a matrix. First, we need to load data.table package in the working space. Installation install.packages("data.table")              Loading library("dat 2 min read Like