How to remove rows that contain all zeros in R dataframe? Last Updated : 27 Mar, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, let's discuss how to rows that contain all zeroes in R dataframe. Approach: Create dataframeGet the sum of each rowSimply remove those rows that have zero-sum. Based on the sum we are getting we will add it to the new dataframe. if the sum is greater than zero then we will add it otherwise not.Display dataframe To calculate the sum of each row rowSums() function can be used. Syntax: df[rowSums(df[])>0,] Where, df is the dataframe. Example 1: R df <- data.frame(x = c(0, 1, 3, 0, 0), y = c(0, 1, 5, 0, 3)) print("data frame is ") print(df) ans = df[rowSums(df[])>0,] print("rows after removing rows that have all zeros") print(ans) Output: Example 2: R a = rep(0,10) b = sample(c(0,1),10,replace=TRUE) df = data.frame(a,b) print("dataframe is ") print(df) ans = df[rowSums(df[])>0,] print("rows after removing rows that have all zeros") print(ans) Output: Comment More infoAdvertise with us Next Article How to remove rows that contain all zeros in R dataframe? K kapilm180265ca Follow Improve Article Tags : R Language R Programs R-DataFrame R DataFrame-Programs Similar Reads How to Conditionally Remove Rows in R DataFrame? In this article, we will discuss how to conditionally remove rows from a dataframe in the R Programming Language. We need to remove some rows of data from the dataframe conditionally to prepare the data. For that, we use logical conditions on the basis of which data that doesn't follow the condition 4 min read How to Remove Rows in R DataFrame? 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 dataframerow_number is the row index position Exam 2 min read How to Remove Rows with Some or All NAs in R DataFrame? In this article, we will discuss how to remove rows with some or all NA's in R Programming Language. We will consider a dataframe and then remove rows in R. Let's create a dataframe with 3 columns and 6 rows. R # create dataframe data = data.frame(names=c("manoj", "bobby", "sravan", "deepu", NA, NA) 2 min read How to remove a subset from a DataFrame in R ? A subset is a combination of cells that form a smaller data frame formed out from the original data frame. A set of rows and columns can be removed from the original data frame to reduce a part of the data frame. The subset removal can be based on constraints to which rows and columns are subjected 4 min read Remove All Whitespace in Each DataFrame Column in R In this article, we will learn how to remove all whitespace in each dataframe column in R programming language. Sample dataframe in use: c1 c2 1 geeks for geeks 2 cs f 3 r -lang gMethod 1: Using gsub() In this approach, we have used apply() function to apply a function to each row in a data frame. T 4 min read Like