VOOZH about

URL: https://www.geeksforgeeks.org/r-language/how-to-remove-rows-in-r-dataframe/

⇱ How to Remove Rows in R DataFrame? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Remove Rows in R DataFrame?

Last Updated : 23 Jul, 2025

In this article, we will discuss how to remove rows from dataframe in the R programming language.

Method 1: Remove Rows by Number

By using a particular row index number we can remove the rows.

Syntax:

data[-c(row_number), ]

where. 

  • data is the input dataframe
  • row_number is the row index position

Example:

Output:

> print(data[-c(4), ])
 name age
1 manoj 21
2 manoja 23
3 manoji 21
5 manooj 22
> print(data[-c(5), ])
 name age
1 manoj 21
2 manoja 23
3 manoji 21
4 mano 10
> print(data[-c(1), ])
 name age
2 manoja 23
3 manoji 21
4 mano 10
5 manooj 22

We can also remove multiple rows by using the slice operator

Syntax:

data[-c(row_number_start:row_number_end), ]

where,

  • data is the input dataframe
  • row_number_start is the starting row number
  • row_number_end is the ending row number

Example:

Output:

 name age
5 manooj 22
>
> # display by removing row from 1 st to 2 nd
> print(data[-c(1:2), ])
 name age
3 manoji 21
4 mano 10
5 manooj 22

We can also remove multiple rows by specifying multiple row indices

Syntax:

data[-c(row numbers), ]

Example:

Output:

 name age
2 manoja 23
5 manooj 22

Method 2: Remove rows conditionally

We can also use the conditions using subset() function

Syntax:

subset(dataframe,condition )

Example:

Output:

 name age
2 manoja 23
5 manooj 22

Method 3: Remove rows with NA values:

we can remove rows that contain NA values using na.omit() function from the given data frame.

Syntax:

na.omit(dataframe)

Example:

Output:

 name age
1 manoj 21
2 manoja 23
3 manoji 21
4 mano 10
5 manooj 22
Comment

Explore