Dplyr filter function within creating a matrix

I am attempting to create two different matrices using the socialmixr package for different locations (home and other locations). Within this I am using the dplyr's filter function to only consider locations required for the function (each location is a column variable with a corresponding TRUE or FALSE attribute per value. When I run these two matrices for different locations, I am getting the exact same matrices. Are there any ways that people would recommend filtering.

#Home matrix (when someone either has had contact with own household (contact_home) or different household (contact_elsehome))

home_matrix <- contact_matrix(data, filter = list((contact_home=TRUE) | (cnt_elsehome=TRUE)), age.limits, survey.pop, weights)

#Other matrix (where people have had contact on transport or outdoors or the store or other forms of contact)

other_plus_matrix <- contact_matrix(data, filter = list((contact_transport=TRUE) | (contact_outdoor=TRUE) | (contact_store=TRUE) | (contact_other=TRUE)), age.limits, survey.pop, weights)

Please let me know if the filtering notation makes sense and if you would recommend any other types of filtering!

In this and the following expression if either side of | evaluates as TRUE then age.limits, survey.pop, weights will return for any given row.

There is no guarantee that the test will not always so evaluate.

While dplyr provides many conveniences, it can be less expressive for logical tests than base.

M <- matrix(rexp(200, rate=.1), ncol=20)
which(M > 20) # all columns, all rows
#>  [1]   5  10  13  21  27  32  34  38  41  55  56  57  63  64  66  98 104 109 113
#> [20] 120 130 132 148 155 157 163 176 180 182 183 199
which(M[,1] > 20) # first column, all rows
#> [1]  5 10

Created on 2020-09-09 by the reprex package (v0.3.0)

This topic was automatically closed 21 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.