I read my excel file in R and i want to remove the negative and zero values from the data, how i can remove it?
Asked
Active
Viewed 168 times
0
-
1How would you like to remove them? Would you like to remove the entire row? By the way it would be much more efficient to help you if you could share a reproducible piece of your data by means of `dput(head(data))`. – Anoushiravan R May 03 '21 at 08:43
3 Answers
1
If you want to delete the entire rows where your column named CO ppm
is <=0 you can simply do :
set.seed(5)
df <- data.frame(a=runif(100,-1,1),CO_ppm=runif(100,-1,1))
x <- df[df$CO_ppm>0,]
#or
x <- df[-df$CO_ppm<=0,]

Elia
- 2,210
- 1
- 6
- 18
1
if you don't have strings or logical values on your data frame, you can try:
pirozi95 <- abs(pirozi95)
pirozi95 <- pirozi95[-which(pirozi95 == 0), ]
or
pirozi95 <- abs(pirozi95)
pirozi95[which(pirozi95 == 0),] <- "NA"

Fabiano Pinheiro Da Silva
- 63
- 1
- 2
- 11
0
You can also use the following code. In this data set I first defined a predicate function . > 0
as you desired and then has chosen to apply it on only numeric variables:
library(dplyr)
df %>%
filter(if_all(where(is.numeric), ~ . > 0)) %>%
slice_head(n = 5)
a CO_ppm
1 0.78304648 0.5654524
2 0.31485792 0.7713410
3 0.29419764 0.5080974
4 0.27490024 0.8666837
5 0.05786812 0.2026275
I used the sample data produced by Mr. @Elia so I would like to thank him for that.

Anoushiravan R
- 21,622
- 3
- 18
- 41