count number of rows greater than a certain value, across a whole data frame

Hi all, I'm trying to find a shortcut to counting up numbers by hand. I have a residual correlation matrix that I want to look at and find all instances of numbers above an absolute value of .1. I've so far written the following code, which takes care of the rounding and absolute value part, but I'm not sure how to tell R to count the number of rows in every column where the value is >.1. Any ideas?

residuals =residuals %>% 
  select(cov.a1_r:cov.c5_r) %>% 
  map_df(round,digits=3) %>% 
  map_df(abs)

See the FAQ: How to do a minimal reproducible example reprex for beginners to be able to receive answers that do not have to employ imagined data.

set.seed(137)
m <- matrix(rexp(200, rate=.1), ncol=20)

which(m[,1:20] < 1, arr.ind = TRUE)
#>       row col
#>  [1,]   2   3
#>  [2,]   1   4
#>  [3,]   2   4
#>  [4,]   3   6
#>  [5,]   9   9
#>  [6,]   3  11
#>  [7,]   7  13
#>  [8,]   6  15
#>  [9,]   9  15
#> [10,]   1  16
#> [11,]  10  16

Thanks,

here is the data as a tribble:

dat=tibble::tribble(
         ~cov.a1_r,      ~cov.a2,      ~cov.a3,      ~cov.a4,      ~cov.a5,      ~cov.o1,    ~cov.o2_r,      ~cov.o3,      ~cov.o4,    ~cov.o5_r,      ~cov.n1,      ~cov.n2,      ~cov.n3,      ~cov.n4,      ~cov.n5,    ~cov.e1_r,    ~cov.e2_r,      ~cov.e3,      ~cov.e4,      ~cov.e5,      ~cov.c1,      ~cov.c2,      ~cov.c3,    ~cov.c4_r,    ~cov.c5_r,
          4.44e-16,  0.127904309,  0.015743852, -0.018694263, -0.043839606, -0.064685296,  0.022668913, -0.011817436,  0.066229809,  0.051036338, -0.104955277, -0.078049076, -0.037047164,  0.001831452,  0.023381317, -0.025334429,  -0.07617074,  -0.09834768,  -0.09547623, -0.109692653, -0.078035472, -0.080848226,  -0.04221649,  0.034338697, -0.032917674,
       0.127904309,    -1.11e-16,  0.017364387,  0.020344318, -0.048044864,   0.01472123, -0.096052661,  0.022993513,  0.036883471, -0.009760208,  0.025766045,  0.065809912,   0.06386381, -0.003840409,  0.092417857, -0.027205295, -0.066126179, -0.022153405, -0.013916634,  0.049544099, -0.016244141,  0.001510095,  0.070626007, -0.005706533,  -0.01307654,
       0.015743852,  0.017364387,    -2.22e-16,  0.002735837,     0.000556,  0.021821148, -0.101483264,  0.061731465, -0.020613664,   -0.0630349,  0.054773301,  0.042012628,  0.081400909, -0.031272912,  0.043928086, -0.078168515, -0.065652146,  0.062535074,  0.027907444,  -0.02943461, -0.023679713, -0.001535661, -0.007314886, -0.054677873, -0.001336923,
      -0.018694263,  0.020344318,  0.002735837,     3.33e-16,  -0.02486017, -0.030180094, -0.102592773, -0.040927855, -0.085770705, -0.098533704, -0.012514298, -0.063853763,  0.008297868, -0.105870088,  0.042261484, -0.062618588, -0.033664609, -0.013626828,  0.074416948, -0.023752783,  0.001068559,  0.125437476,  0.040174284,  0.052738816,  0.143973232,
      -0.043839606, -0.048044864,     0.000556,  -0.02486017,    -1.11e-16,  0.044953705, -0.080016101,  0.087214863, -0.037147631,   -0.0456658, -0.078199431, -0.075487135, -0.027925201, -0.127475718, -0.004323528, -0.012332448,  0.010648049,  0.117781485,  0.152637793,  0.009167689,  0.008214824, -0.018888782,  0.005423538, -0.035710466,  0.024757589,
      -0.064685296,   0.01472123,  0.021821148, -0.030180094,  0.044953705,            0,  -0.00516933, -0.015379653,  0.045679375, -0.013439115,     0.000872,  0.007800033,  0.005855622, -0.012503411,  -0.09738656, -0.039507599, -0.019958736,  0.168146349, -0.041802914,  0.149759705,  0.085681064,  0.060567502, -0.001623448, -0.025731934, -0.019667923,
       0.022668913, -0.096052661, -0.101483264, -0.102592773, -0.080016101,  -0.00516933,    -2.22e-16, -0.018639437, -0.022367766,  0.135443974, -0.096364518, -0.079548776, -0.070313599, -0.047032417, -0.163099897, -0.057061019, -0.053230976, -0.044288153, -0.182564229, -0.020071821,  0.060123009, -0.017501695, -0.038895269,  0.119898331,   0.04444528,
      -0.011817436,  0.022993513,  0.061731465, -0.040927855,  0.087214863, -0.015379653, -0.018639437,            0,  0.015551595, -0.023448613,  0.027621871,  0.035607248,  0.030156552, -0.016519481, -0.039823511,  0.032302296,  0.008961689,   0.20100828, -0.015211485,   0.12445226,  0.076470656,   0.06386828, -0.060205248, -0.070079226, -0.060938225,
       0.066229809,  0.036883471, -0.020613664, -0.085770705, -0.037147631,  0.045679375, -0.022367766,  0.015551595,    -2.22e-16,  0.075001496,  0.100302994,  0.151881615,  0.184524383,  0.235065973,  0.124571578, -0.153716154, -0.245553377, -0.013224918, -0.173447273, -0.059207122,  0.061615313,  0.005997114,  -0.02688485, -0.102197828, -0.178901127,
       0.051036338, -0.009760208,   -0.0630349, -0.098533704,   -0.0456658, -0.013439115,  0.135443974, -0.023448613,  0.075001496,            0, -0.063616178,  0.017090179,  -0.01936957, -0.006224873, -0.112426184, -0.028813925, -0.064201052, -0.007730017, -0.194168979, -0.002081089,  0.054019934, -0.015389604, -0.073007306,  0.092086455, -0.030157062,
      -0.104955277,  0.025766045,  0.054773301, -0.012514298, -0.078199431,     0.000872, -0.096364518,  0.027621871,  0.100302994, -0.063616178,            0,  0.056006482, -0.027020059,  -0.06275298, -0.034148367,  0.098493124, -0.035155406,  0.079254648, -0.002318732,  0.145488037,  0.056407327,  0.118465732,  0.048103284, -0.052187823, -0.071666977,
      -0.078049076,  0.065809912,  0.042012628, -0.063853763, -0.075487135,  0.007800033, -0.079548776,  0.035607248,  0.151881615,  0.017090179,  0.056006482,     3.33e-16, -0.028289615, -0.064996151,  -0.05265392,  0.090399992, -0.069714761,  0.062975593, -0.014305893,  0.147261672,  0.086919829,  0.128719232,   0.05714951,  0.001131034, -0.105573549,
      -0.037047164,   0.06386381,  0.081400909,  0.008297868, -0.027925201,  0.005855622, -0.070313599,  0.030156552,  0.184524383,  -0.01936957, -0.027020059, -0.028289615,    -2.22e-16,   0.11058195,  0.068485046,  0.044285393, -0.070389333,  0.093343076,     0.000714,  0.031958795,  0.086634891,  0.124022962,  0.033680913, -0.058964745,   -0.1152138,
       0.001831452, -0.003840409, -0.031272912, -0.105870088, -0.127475718, -0.012503411, -0.047032417, -0.016519481,  0.235065973, -0.006224873,  -0.06275298, -0.064996151,   0.11058195,    -1.11e-16,  0.114957556, -0.156363204,  -0.25342551, -0.059173001, -0.208529359, -0.129813335, -0.008920589,  0.051774409, -0.033875858, -0.157010268, -0.254168964,
       0.023381317,  0.092417857,  0.043928086,  0.042261484, -0.004323528,  -0.09738656, -0.163099897, -0.039823511,  0.124571578, -0.112426184, -0.034148367,  -0.05265392,  0.068485046,  0.114957556,    -1.11e-16,  0.014963262,  -0.17340063, -0.002904567, -0.017598837, -0.074018714,  0.030196511,  0.135655345,  0.053937903, -0.097396093, -0.090789303,
      -0.025334429, -0.027205295, -0.078168515, -0.062618588, -0.012332448, -0.039507599, -0.057061019,  0.032302296, -0.153716154, -0.028813925,  0.098493124,  0.090399992,  0.044285393, -0.156363204,  0.014963262,     2.22e-16,  0.074806786, -0.031267073,  0.022703523,  -0.00478754, -0.080642391, -0.136208554,  -0.10117772, -0.043199945, -0.057263843,
       -0.07617074, -0.066126179, -0.065652146, -0.033664609,  0.010648049, -0.019958736, -0.053230976,  0.008961689, -0.245553377, -0.064201052, -0.035155406, -0.069714761, -0.070389333,  -0.25342551,  -0.17340063,  0.074806786,    -1.11e-16, -0.052491865,  0.035769851, -0.003723108, -0.030712871, -0.073297448, -0.046995253,  0.032484125,  0.111173885,
       -0.09834768, -0.022153405,  0.062535074, -0.013626828,  0.117781485,  0.168146349, -0.044288153,   0.20100828, -0.013224918, -0.007730017,  0.079254648,  0.062975593,  0.093343076, -0.059173001, -0.002904567, -0.031267073, -0.052491865,     3.33e-16, -0.023943127,  0.044057496,  0.011262828,  0.020646094, -0.029917982,  -0.07290102,  0.024465744,
       -0.09547623, -0.013916634,  0.027907444,  0.074416948,  0.152637793, -0.041802914, -0.182564229, -0.015211485, -0.173447273, -0.194168979, -0.002318732, -0.014305893,     0.000714, -0.208529359, -0.017598837,  0.022703523,  0.035769851, -0.023943127,            0, -0.065623194,  0.014606672, -0.025460995,  -0.03794066, -0.064149262,  0.051552584,
      -0.109692653,  0.049544099,  -0.02943461, -0.023752783,  0.009167689,  0.149759705, -0.020071821,   0.12445226, -0.059207122, -0.002081089,  0.145488037,  0.147261672,  0.031958795, -0.129813335, -0.074018714,  -0.00478754, -0.003723108,  0.044057496, -0.065623194,     3.33e-16,  0.158960923,  0.140656923,  0.099590195,  0.096195857,  0.112149564,
      -0.078035472, -0.016244141, -0.023679713,  0.001068559,  0.008214824,  0.085681064,  0.060123009,  0.076470656,  0.061615313,  0.054019934,  0.056407327,  0.086919829,  0.086634891, -0.008920589,  0.030196511, -0.080642391, -0.030712871,  0.011262828,  0.014606672,  0.158960923,     2.22e-16,  0.112265274,  0.016434925, -0.024393806, -0.080471562,
      -0.080848226,  0.001510095, -0.001535661,  0.125437476, -0.018888782,  0.060567502, -0.017501695,   0.06386828,  0.005997114, -0.015389604,  0.118465732,  0.128719232,  0.124022962,  0.051774409,  0.135655345, -0.136208554, -0.073297448,  0.020646094, -0.025460995,  0.140656923,  0.112265274,     3.33e-16,  0.039766915, -0.019569523, -0.063606237,
       -0.04221649,  0.070626007, -0.007314886,  0.040174284,  0.005423538, -0.001623448, -0.038895269, -0.060205248,  -0.02688485, -0.073007306,  0.048103284,   0.05714951,  0.033680913, -0.033875858,  0.053937903,  -0.10117772, -0.046995253, -0.029917982,  -0.03794066,  0.099590195,  0.016434925,  0.039766915,            0, -0.025709004,  0.012416139,
       0.034338697, -0.005706533, -0.054677873,  0.052738816, -0.035710466, -0.025731934,  0.119898331, -0.070079226, -0.102197828,  0.092086455, -0.052187823,  0.001131034, -0.058964745, -0.157010268, -0.097396093, -0.043199945,  0.032484125,  -0.07290102, -0.064149262,  0.096195857, -0.024393806, -0.019569523, -0.025709004,    -2.22e-16,  0.052085966,
      -0.032917674,  -0.01307654, -0.001336923,  0.143973232,  0.024757589, -0.019667923,   0.04444528, -0.060938225, -0.178901127, -0.030157062, -0.071666977, -0.105573549,   -0.1152138, -0.254168964, -0.090789303, -0.057263843,  0.111173885,  0.024465744,  0.051552584,  0.112149564, -0.080471562, -0.063606237,  0.012416139,  0.052085966,    -2.22e-16
      )

dat=tibble::tribble(
  ~cov.a1_r,      ~cov.a2,      ~cov.a3,      ~cov.a4,      ~cov.a5,      ~cov.o1,    ~cov.o2_r,      ~cov.o3,      ~cov.o4,    ~cov.o5_r,      ~cov.n1,      ~cov.n2,      ~cov.n3,      ~cov.n4,      ~cov.n5,    ~cov.e1_r,    ~cov.e2_r,      ~cov.e3,      ~cov.e4,      ~cov.e5,      ~cov.c1,      ~cov.c2,      ~cov.c3,    ~cov.c4_r,    ~cov.c5_r,
  4.44e-16,  0.127904309,  0.015743852, -0.018694263, -0.043839606, -0.064685296,  0.022668913, -0.011817436,  0.066229809,  0.051036338, -0.104955277, -0.078049076, -0.037047164,  0.001831452,  0.023381317, -0.025334429,  -0.07617074,  -0.09834768,  -0.09547623, -0.109692653, -0.078035472, -0.080848226,  -0.04221649,  0.034338697, -0.032917674,
  0.127904309,    -1.11e-16,  0.017364387,  0.020344318, -0.048044864,   0.01472123, -0.096052661,  0.022993513,  0.036883471, -0.009760208,  0.025766045,  0.065809912,   0.06386381, -0.003840409,  0.092417857, -0.027205295, -0.066126179, -0.022153405, -0.013916634,  0.049544099, -0.016244141,  0.001510095,  0.070626007, -0.005706533,  -0.01307654,
  0.015743852,  0.017364387,    -2.22e-16,  0.002735837,     0.000556,  0.021821148, -0.101483264,  0.061731465, -0.020613664,   -0.0630349,  0.054773301,  0.042012628,  0.081400909, -0.031272912,  0.043928086, -0.078168515, -0.065652146,  0.062535074,  0.027907444,  -0.02943461, -0.023679713, -0.001535661, -0.007314886, -0.054677873, -0.001336923,
  -0.018694263,  0.020344318,  0.002735837,     3.33e-16,  -0.02486017, -0.030180094, -0.102592773, -0.040927855, -0.085770705, -0.098533704, -0.012514298, -0.063853763,  0.008297868, -0.105870088,  0.042261484, -0.062618588, -0.033664609, -0.013626828,  0.074416948, -0.023752783,  0.001068559,  0.125437476,  0.040174284,  0.052738816,  0.143973232,
  -0.043839606, -0.048044864,     0.000556,  -0.02486017,    -1.11e-16,  0.044953705, -0.080016101,  0.087214863, -0.037147631,   -0.0456658, -0.078199431, -0.075487135, -0.027925201, -0.127475718, -0.004323528, -0.012332448,  0.010648049,  0.117781485,  0.152637793,  0.009167689,  0.008214824, -0.018888782,  0.005423538, -0.035710466,  0.024757589,
  -0.064685296,   0.01472123,  0.021821148, -0.030180094,  0.044953705,            0,  -0.00516933, -0.015379653,  0.045679375, -0.013439115,     0.000872,  0.007800033,  0.005855622, -0.012503411,  -0.09738656, -0.039507599, -0.019958736,  0.168146349, -0.041802914,  0.149759705,  0.085681064,  0.060567502, -0.001623448, -0.025731934, -0.019667923,
  0.022668913, -0.096052661, -0.101483264, -0.102592773, -0.080016101,  -0.00516933,    -2.22e-16, -0.018639437, -0.022367766,  0.135443974, -0.096364518, -0.079548776, -0.070313599, -0.047032417, -0.163099897, -0.057061019, -0.053230976, -0.044288153, -0.182564229, -0.020071821,  0.060123009, -0.017501695, -0.038895269,  0.119898331,   0.04444528,
  -0.011817436,  0.022993513,  0.061731465, -0.040927855,  0.087214863, -0.015379653, -0.018639437,            0,  0.015551595, -0.023448613,  0.027621871,  0.035607248,  0.030156552, -0.016519481, -0.039823511,  0.032302296,  0.008961689,   0.20100828, -0.015211485,   0.12445226,  0.076470656,   0.06386828, -0.060205248, -0.070079226, -0.060938225,
  0.066229809,  0.036883471, -0.020613664, -0.085770705, -0.037147631,  0.045679375, -0.022367766,  0.015551595,    -2.22e-16,  0.075001496,  0.100302994,  0.151881615,  0.184524383,  0.235065973,  0.124571578, -0.153716154, -0.245553377, -0.013224918, -0.173447273, -0.059207122,  0.061615313,  0.005997114,  -0.02688485, -0.102197828, -0.178901127,
  0.051036338, -0.009760208,   -0.0630349, -0.098533704,   -0.0456658, -0.013439115,  0.135443974, -0.023448613,  0.075001496,            0, -0.063616178,  0.017090179,  -0.01936957, -0.006224873, -0.112426184, -0.028813925, -0.064201052, -0.007730017, -0.194168979, -0.002081089,  0.054019934, -0.015389604, -0.073007306,  0.092086455, -0.030157062,
  -0.104955277,  0.025766045,  0.054773301, -0.012514298, -0.078199431,     0.000872, -0.096364518,  0.027621871,  0.100302994, -0.063616178,            0,  0.056006482, -0.027020059,  -0.06275298, -0.034148367,  0.098493124, -0.035155406,  0.079254648, -0.002318732,  0.145488037,  0.056407327,  0.118465732,  0.048103284, -0.052187823, -0.071666977,
  -0.078049076,  0.065809912,  0.042012628, -0.063853763, -0.075487135,  0.007800033, -0.079548776,  0.035607248,  0.151881615,  0.017090179,  0.056006482,     3.33e-16, -0.028289615, -0.064996151,  -0.05265392,  0.090399992, -0.069714761,  0.062975593, -0.014305893,  0.147261672,  0.086919829,  0.128719232,   0.05714951,  0.001131034, -0.105573549,
  -0.037047164,   0.06386381,  0.081400909,  0.008297868, -0.027925201,  0.005855622, -0.070313599,  0.030156552,  0.184524383,  -0.01936957, -0.027020059, -0.028289615,    -2.22e-16,   0.11058195,  0.068485046,  0.044285393, -0.070389333,  0.093343076,     0.000714,  0.031958795,  0.086634891,  0.124022962,  0.033680913, -0.058964745,   -0.1152138,
  0.001831452, -0.003840409, -0.031272912, -0.105870088, -0.127475718, -0.012503411, -0.047032417, -0.016519481,  0.235065973, -0.006224873,  -0.06275298, -0.064996151,   0.11058195,    -1.11e-16,  0.114957556, -0.156363204,  -0.25342551, -0.059173001, -0.208529359, -0.129813335, -0.008920589,  0.051774409, -0.033875858, -0.157010268, -0.254168964,
  0.023381317,  0.092417857,  0.043928086,  0.042261484, -0.004323528,  -0.09738656, -0.163099897, -0.039823511,  0.124571578, -0.112426184, -0.034148367,  -0.05265392,  0.068485046,  0.114957556,    -1.11e-16,  0.014963262,  -0.17340063, -0.002904567, -0.017598837, -0.074018714,  0.030196511,  0.135655345,  0.053937903, -0.097396093, -0.090789303,
  -0.025334429, -0.027205295, -0.078168515, -0.062618588, -0.012332448, -0.039507599, -0.057061019,  0.032302296, -0.153716154, -0.028813925,  0.098493124,  0.090399992,  0.044285393, -0.156363204,  0.014963262,     2.22e-16,  0.074806786, -0.031267073,  0.022703523,  -0.00478754, -0.080642391, -0.136208554,  -0.10117772, -0.043199945, -0.057263843,
  -0.07617074, -0.066126179, -0.065652146, -0.033664609,  0.010648049, -0.019958736, -0.053230976,  0.008961689, -0.245553377, -0.064201052, -0.035155406, -0.069714761, -0.070389333,  -0.25342551,  -0.17340063,  0.074806786,    -1.11e-16, -0.052491865,  0.035769851, -0.003723108, -0.030712871, -0.073297448, -0.046995253,  0.032484125,  0.111173885,
  -0.09834768, -0.022153405,  0.062535074, -0.013626828,  0.117781485,  0.168146349, -0.044288153,   0.20100828, -0.013224918, -0.007730017,  0.079254648,  0.062975593,  0.093343076, -0.059173001, -0.002904567, -0.031267073, -0.052491865,     3.33e-16, -0.023943127,  0.044057496,  0.011262828,  0.020646094, -0.029917982,  -0.07290102,  0.024465744,
  -0.09547623, -0.013916634,  0.027907444,  0.074416948,  0.152637793, -0.041802914, -0.182564229, -0.015211485, -0.173447273, -0.194168979, -0.002318732, -0.014305893,     0.000714, -0.208529359, -0.017598837,  0.022703523,  0.035769851, -0.023943127,            0, -0.065623194,  0.014606672, -0.025460995,  -0.03794066, -0.064149262,  0.051552584,
  -0.109692653,  0.049544099,  -0.02943461, -0.023752783,  0.009167689,  0.149759705, -0.020071821,   0.12445226, -0.059207122, -0.002081089,  0.145488037,  0.147261672,  0.031958795, -0.129813335, -0.074018714,  -0.00478754, -0.003723108,  0.044057496, -0.065623194,     3.33e-16,  0.158960923,  0.140656923,  0.099590195,  0.096195857,  0.112149564,
  -0.078035472, -0.016244141, -0.023679713,  0.001068559,  0.008214824,  0.085681064,  0.060123009,  0.076470656,  0.061615313,  0.054019934,  0.056407327,  0.086919829,  0.086634891, -0.008920589,  0.030196511, -0.080642391, -0.030712871,  0.011262828,  0.014606672,  0.158960923,     2.22e-16,  0.112265274,  0.016434925, -0.024393806, -0.080471562,
  -0.080848226,  0.001510095, -0.001535661,  0.125437476, -0.018888782,  0.060567502, -0.017501695,   0.06386828,  0.005997114, -0.015389604,  0.118465732,  0.128719232,  0.124022962,  0.051774409,  0.135655345, -0.136208554, -0.073297448,  0.020646094, -0.025460995,  0.140656923,  0.112265274,     3.33e-16,  0.039766915, -0.019569523, -0.063606237,
  -0.04221649,  0.070626007, -0.007314886,  0.040174284,  0.005423538, -0.001623448, -0.038895269, -0.060205248,  -0.02688485, -0.073007306,  0.048103284,   0.05714951,  0.033680913, -0.033875858,  0.053937903,  -0.10117772, -0.046995253, -0.029917982,  -0.03794066,  0.099590195,  0.016434925,  0.039766915,            0, -0.025709004,  0.012416139,
  0.034338697, -0.005706533, -0.054677873,  0.052738816, -0.035710466, -0.025731934,  0.119898331, -0.070079226, -0.102197828,  0.092086455, -0.052187823,  0.001131034, -0.058964745, -0.157010268, -0.097396093, -0.043199945,  0.032484125,  -0.07290102, -0.064149262,  0.096195857, -0.024393806, -0.019569523, -0.025709004,    -2.22e-16,  0.052085966,
  -0.032917674,  -0.01307654, -0.001336923,  0.143973232,  0.024757589, -0.019667923,   0.04444528, -0.060938225, -0.178901127, -0.030157062, -0.071666977, -0.105573549,   -0.1152138, -0.254168964, -0.090789303, -0.057263843,  0.111173885,  0.024465744,  0.051552584,  0.112149564, -0.080471562, -0.063606237,  0.012416139,  0.052085966,    -2.22e-16
)

idx <- which(dat[,seq_along(dat)] > abs(0.1), arr.ind = TRUE)
length(unique(idx[,1]))
#> [1] 22
1 Like

I'm not that familiar with tribbles, but with data frames there are many ways to do that. E.g, suppose that I'd like to test how many values are greater than 1 in each column of a data frame, then:

d <- data.frame(a=1:5,b= -2:2, c=7:11);
d
  a  b  c
1 1 -2  7
2 2 -1  8
3 3  0  9
4 4  1 10
5 5  2 11
d.tst <- ifelse(d > 1, 1, 0) %>% as.data.frame
d.tst
  a b c
1 0 0 1
2 1 0 1
3 1 0 1
4 1 0 1
5 1 1 1
colwise(sum)(d.tst)
  a b c
1 4 1 5

Basically what I did here is applied the test ">1" for the whole data frame (I could do just d > 1 and get TRUE/FALSE values instead, but 0 and 1 are more convenient for the next step). The I applied the sum function for each column, using the colwise function, which gives you the number of "1s" in wch column. (colwise basically takes a function to be applied for each column, and returns a function that takes a data frame and applies that function for each of its columns; I know that there are equivalent methods for types other than data frames).

I played a bit with a reduced variant of your example with tribble and I think I managed to get the similar method working there, but as said I'm not familiar enough to demonstrate using that code.

Hope that helps.

1 Like

This was extremely helpful, thank you!!

Sure thing, glad I could help :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.