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

select columns based on range condition and containing also NA values

$
0
0

Based on my question here

I have a dataset : I want to keep columns based on values range : all values of subsetted columns must be between 99 an 1000.

 var1 <- c(333, NA, 456)
 var2 <- c(3, 10, 500)
 var3 <- c(356, 813, 856)
 var4 <- c("aaa", "bbb", "ccc")
 var5 <- c(NA, 111, 989)

dataset <- data.frame(var1, var2, var3, var4, var5)

It works well without NA values

dataset %>%
select_if(~ is.numeric(.) && all(between(., 99, 1000)))

or

purrr::keep(dataset, ~is.numeric(.) && min(.) >= 99 && max(.) <= 1000)

but when I introduce NA in my data :

select_if function returns me this error :
"Only strings can be converted to symbols"

puur::keep function returns me this error : "Predicate functions must return a single TRUE or FALSE, not a missing value"

How can I manage NA ? Select columns based on values range containing alos NA values ?


Viewing all articles
Browse latest Browse all 201919

Trending Articles



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