Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201943

Remove rows from dataframe if they contain a certain value (R ,dplyr)

$
0
0

I have a dataframe, df. I would like to remove all rows that contain the value 0 from the dataframe.

  ID     Value

  A      8
  A      8
  A      0
  B      1
  B      2
  C      0

Desired outcome:

 ID     Value

 A      8
 A      8
 B      1
 B      2

Here is the dput:

 structure(list(ID = structure(c(1L, 1L, 1L, 2L, 2L, 3L), .Label = c("A", 
 "B", "C"), class = "factor"), Value = c(8L, 8L, 0L, 1L, 2L, 0L
 )), class = "data.frame", row.names = c(NA, -6L))

This is what I tried:

 I was using the same concept to remove a column:

 library(dplyr)
 df%>% select(-c() 

 However, I am unsure how to specify how to remove the row if and only if it contains a 0.

Viewing all articles
Browse latest Browse all 201943

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>