I have a big tibble having 7000 rows and 10000 columns. I want to filter row if it has at least one non zero element across all columns. I wrote the following code which works fine on small tibble. As soon as I increases number of columns it breaks
Can anyone tell where is the glitch ?
Thanks.
library(tidyverse)
ncol = 10000
nrow = 7000
rr = sample(c(0,1) , nrow * ncol , replace = TRUE) %>%
matrix(ncol = ncol) %>%
as.data.frame() %>%
as_tibble()
rr %>% dplyr::filter_if(is.numeric , .vars_predicate = any_vars(. != 0 ))
#> Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Created on 2019-07-19 by the reprex package (v0.3.0)
filter_ifbut the base R alternative works fine.rr[rowSums(rr != 0) > 0, ]