class: center, middle, inverse, title-slide # How to Use the
filter()
function for numeric values ## Selecting specific rows ### Peter Higgins ### 2020-12-31 --- ### How to Use Filter to Pick Out a Subset of Rows #### We will Start with Numeric Variables Format: <br> `dataset %>% filter(var > value)` # you can use <=, ==, <, >, >=, != etc. What is in the parentheses **must** evaluate to a logical vector, <br> e.g, a string of TRUE or FALSE values, one for each row in your dataset. You can Remember that filte**R** is for selecting **R**ows because it ends with an **R**. Remember that **testing for equality** in a logic test requires 2 = =, not just one =. This is a **very** common syntax error in R code. You can also use *near* to get numbers in a range Let's look at some examples! --- count: false Example 1/6: filter prostate data for cases with cancer recurrence == 1 .panel1-filter1-auto[ ```r # how many rows when you start *nrow(prostate) ``` ] .panel2-filter1-auto[ ``` [1] 316 ``` ] --- count: false Example 1/6: filter prostate data for cases with cancer recurrence == 1 .panel1-filter1-auto[ ```r # how many rows when you start nrow(prostate) *prostate ``` ] .panel2-filter1-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 20 rbc_age_group median_rbc_age age aa fam_hx p_vol t_vol t_stage b_gs <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 3 25 72.1 0 0 54 3 1 3 2 3 25 73.6 0 0 43.2 3 2 2 3 3 25 67.5 0 0 103. 1 1 3 4 2 15 65.8 0 0 46 1 1 1 5 2 15 63.2 0 0 60 2 1 2 6 3 25 65.4 0 0 45.9 2 1 1 7 3 25 65.5 1 0 42.6 2 1 1 8 1 10 67.1 0 0 40.7 3 1 1 9 1 10 63.9 0 0 45 2 1 1 10 2 15 63 1 0 67.6 2 1 2 # … with 306 more rows, and 11 more variables: bn <dbl>, organ_confined <dbl>, # preop_psa <dbl>, preop_therapy <dbl>, units <dbl>, s_gs <dbl>, # any_adj_therapy <dbl>, adj_rad_therapy <dbl>, recurrence <dbl>, # censor <dbl>, time_to_recurrence <dbl> ``` ] --- count: false Example 1/6: filter prostate data for cases with cancer recurrence == 1 .panel1-filter1-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns * select(age, aa, fam_hx, recurrence) ``` ] .panel2-filter1-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 4 age aa fam_hx recurrence <dbl> <dbl> <dbl> <dbl> 1 72.1 0 0 1 2 73.6 0 0 1 3 67.5 0 0 0 4 65.8 0 0 0 5 63.2 0 0 0 6 65.4 0 0 0 7 65.5 1 0 0 8 67.1 0 0 1 9 63.9 0 0 0 10 63 1 0 0 # … with 306 more rows ``` ] --- count: false Example 1/6: filter prostate data for cases with cancer recurrence == 1 .panel1-filter1-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, aa, fam_hx, recurrence) %>% * filter(recurrence == 1) ``` ] .panel2-filter1-auto[ ``` [1] 316 ``` ``` # A tibble: 54 x 4 age aa fam_hx recurrence <dbl> <dbl> <dbl> <dbl> 1 72.1 0 0 1 2 73.6 0 0 1 3 67.1 0 0 1 4 64.4 0 0 1 5 69 1 0 1 6 63.4 1 0 1 7 70.4 1 0 1 8 65.3 1 0 1 9 60.8 0 0 1 10 72.1 0 1 1 # … with 44 more rows ``` ] --- count: false Example 1/6: filter prostate data for cases with cancer recurrence == 1 .panel1-filter1-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, aa, fam_hx, recurrence) %>% filter(recurrence == 1) # see how many rows x cols now # # Format: *# filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter1-auto[ ``` [1] 316 ``` ``` # A tibble: 54 x 4 age aa fam_hx recurrence <dbl> <dbl> <dbl> <dbl> 1 72.1 0 0 1 2 73.6 0 0 1 3 67.1 0 0 1 4 64.4 0 0 1 5 69 1 0 1 6 63.4 1 0 1 7 70.4 1 0 1 8 65.3 1 0 1 9 60.8 0 0 1 10 72.1 0 1 1 # … with 44 more rows ``` ] --- count: false Example 1/6: filter prostate data for cases with cancer recurrence == 1 .panel1-filter1-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, aa, fam_hx, recurrence) %>% filter(recurrence == 1) # see how many rows x cols now # # Format: # filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter1-auto[ ``` [1] 316 ``` ``` # A tibble: 54 x 4 age aa fam_hx recurrence <dbl> <dbl> <dbl> <dbl> 1 72.1 0 0 1 2 73.6 0 0 1 3 67.1 0 0 1 4 64.4 0 0 1 5 69 1 0 1 6 63.4 1 0 1 7 70.4 1 0 1 8 65.3 1 0 1 9 60.8 0 0 1 10 72.1 0 1 1 # … with 44 more rows ``` ] <style> .panel1-filter1-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-filter1-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-filter1-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false Example 2/6: Filter Preoperative PSA for Values > 20 .panel1-filter2-auto[ ```r # how many rows when you start *nrow(prostate) ``` ] .panel2-filter2-auto[ ``` [1] 316 ``` ] --- count: false Example 2/6: Filter Preoperative PSA for Values > 20 .panel1-filter2-auto[ ```r # how many rows when you start nrow(prostate) *prostate ``` ] .panel2-filter2-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 20 rbc_age_group median_rbc_age age aa fam_hx p_vol t_vol t_stage b_gs <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 3 25 72.1 0 0 54 3 1 3 2 3 25 73.6 0 0 43.2 3 2 2 3 3 25 67.5 0 0 103. 1 1 3 4 2 15 65.8 0 0 46 1 1 1 5 2 15 63.2 0 0 60 2 1 2 6 3 25 65.4 0 0 45.9 2 1 1 7 3 25 65.5 1 0 42.6 2 1 1 8 1 10 67.1 0 0 40.7 3 1 1 9 1 10 63.9 0 0 45 2 1 1 10 2 15 63 1 0 67.6 2 1 2 # … with 306 more rows, and 11 more variables: bn <dbl>, organ_confined <dbl>, # preop_psa <dbl>, preop_therapy <dbl>, units <dbl>, s_gs <dbl>, # any_adj_therapy <dbl>, adj_rad_therapy <dbl>, recurrence <dbl>, # censor <dbl>, time_to_recurrence <dbl> ``` ] --- count: false Example 2/6: Filter Preoperative PSA for Values > 20 .panel1-filter2-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns * select(age, recurrence, preop_psa) ``` ] .panel2-filter2-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 72.1 1 14.1 2 73.6 1 10.5 3 67.5 0 6.98 4 65.8 0 4.4 5 63.2 0 21.4 6 65.4 0 5.1 7 65.5 0 6.03 8 67.1 1 8.7 9 63.9 0 3.83 10 63 0 7.98 # … with 306 more rows ``` ] --- count: false Example 2/6: Filter Preoperative PSA for Values > 20 .panel1-filter2-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% * filter(preop_psa > 20) ``` ] .panel2-filter2-auto[ ``` [1] 316 ``` ``` # A tibble: 17 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 63.2 0 21.4 2 73.3 0 30.6 3 67.9 0 29 4 68 0 20.7 5 49.9 0 29.7 6 51.1 1 24.9 7 68.9 1 27 8 65.8 0 22.9 9 60.1 0 22.3 10 50.8 1 37 11 66.1 1 26.1 12 50.9 0 26.2 13 71.9 0 27.7 14 56.5 1 40.1 15 53 0 39 16 59.6 0 31.0 17 51.9 1 27.2 ``` ] --- count: false Example 2/6: Filter Preoperative PSA for Values > 20 .panel1-filter2-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(preop_psa > 20) # see how many rows now # # Format: *# filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter2-auto[ ``` [1] 316 ``` ``` # A tibble: 17 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 63.2 0 21.4 2 73.3 0 30.6 3 67.9 0 29 4 68 0 20.7 5 49.9 0 29.7 6 51.1 1 24.9 7 68.9 1 27 8 65.8 0 22.9 9 60.1 0 22.3 10 50.8 1 37 11 66.1 1 26.1 12 50.9 0 26.2 13 71.9 0 27.7 14 56.5 1 40.1 15 53 0 39 16 59.6 0 31.0 17 51.9 1 27.2 ``` ] --- count: false Example 2/6: Filter Preoperative PSA for Values > 20 .panel1-filter2-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(preop_psa > 20) # see how many rows now # # Format: # filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter2-auto[ ``` [1] 316 ``` ``` # A tibble: 17 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 63.2 0 21.4 2 73.3 0 30.6 3 67.9 0 29 4 68 0 20.7 5 49.9 0 29.7 6 51.1 1 24.9 7 68.9 1 27 8 65.8 0 22.9 9 60.1 0 22.3 10 50.8 1 37 11 66.1 1 26.1 12 50.9 0 26.2 13 71.9 0 27.7 14 56.5 1 40.1 15 53 0 39 16 59.6 0 31.0 17 51.9 1 27.2 ``` ] <style> .panel1-filter2-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-filter2-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-filter2-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false Example 3/6: Filter Preoperative PSA for Values very close to 10 .panel1-filter3-auto[ ```r # how many rows when you start *nrow(prostate) ``` ] .panel2-filter3-auto[ ``` [1] 316 ``` ] --- count: false Example 3/6: Filter Preoperative PSA for Values very close to 10 .panel1-filter3-auto[ ```r # how many rows when you start nrow(prostate) *prostate ``` ] .panel2-filter3-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 20 rbc_age_group median_rbc_age age aa fam_hx p_vol t_vol t_stage b_gs <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 3 25 72.1 0 0 54 3 1 3 2 3 25 73.6 0 0 43.2 3 2 2 3 3 25 67.5 0 0 103. 1 1 3 4 2 15 65.8 0 0 46 1 1 1 5 2 15 63.2 0 0 60 2 1 2 6 3 25 65.4 0 0 45.9 2 1 1 7 3 25 65.5 1 0 42.6 2 1 1 8 1 10 67.1 0 0 40.7 3 1 1 9 1 10 63.9 0 0 45 2 1 1 10 2 15 63 1 0 67.6 2 1 2 # … with 306 more rows, and 11 more variables: bn <dbl>, organ_confined <dbl>, # preop_psa <dbl>, preop_therapy <dbl>, units <dbl>, s_gs <dbl>, # any_adj_therapy <dbl>, adj_rad_therapy <dbl>, recurrence <dbl>, # censor <dbl>, time_to_recurrence <dbl> ``` ] --- count: false Example 3/6: Filter Preoperative PSA for Values very close to 10 .panel1-filter3-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns * select(age, recurrence, preop_psa) ``` ] .panel2-filter3-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 72.1 1 14.1 2 73.6 1 10.5 3 67.5 0 6.98 4 65.8 0 4.4 5 63.2 0 21.4 6 65.4 0 5.1 7 65.5 0 6.03 8 67.1 1 8.7 9 63.9 0 3.83 10 63 0 7.98 # … with 306 more rows ``` ] --- count: false Example 3/6: Filter Preoperative PSA for Values very close to 10 .panel1-filter3-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% * filter(near(preop_psa, 10)) ``` ] .panel2-filter3-auto[ ``` [1] 316 ``` ``` # A tibble: 2 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 55.8 0 10 2 57.1 0 10 ``` ] --- count: false Example 3/6: Filter Preoperative PSA for Values very close to 10 .panel1-filter3-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(near(preop_psa, 10)) # see how many rows now # # Format: *# filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter3-auto[ ``` [1] 316 ``` ``` # A tibble: 2 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 55.8 0 10 2 57.1 0 10 ``` ] --- count: false Example 3/6: Filter Preoperative PSA for Values very close to 10 .panel1-filter3-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(near(preop_psa, 10)) # see how many rows now # # Format: # filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter3-auto[ ``` [1] 316 ``` ``` # A tibble: 2 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 55.8 0 10 2 57.1 0 10 ``` ] <style> .panel1-filter3-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-filter3-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-filter3-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false Example 4/6: Filter Preoperative PSA for Values within 1.5 units of 17 .panel1-filter4-auto[ ```r # how many rows when you start *nrow(prostate) ``` ] .panel2-filter4-auto[ ``` [1] 316 ``` ] --- count: false Example 4/6: Filter Preoperative PSA for Values within 1.5 units of 17 .panel1-filter4-auto[ ```r # how many rows when you start nrow(prostate) *prostate ``` ] .panel2-filter4-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 20 rbc_age_group median_rbc_age age aa fam_hx p_vol t_vol t_stage b_gs <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 3 25 72.1 0 0 54 3 1 3 2 3 25 73.6 0 0 43.2 3 2 2 3 3 25 67.5 0 0 103. 1 1 3 4 2 15 65.8 0 0 46 1 1 1 5 2 15 63.2 0 0 60 2 1 2 6 3 25 65.4 0 0 45.9 2 1 1 7 3 25 65.5 1 0 42.6 2 1 1 8 1 10 67.1 0 0 40.7 3 1 1 9 1 10 63.9 0 0 45 2 1 1 10 2 15 63 1 0 67.6 2 1 2 # … with 306 more rows, and 11 more variables: bn <dbl>, organ_confined <dbl>, # preop_psa <dbl>, preop_therapy <dbl>, units <dbl>, s_gs <dbl>, # any_adj_therapy <dbl>, adj_rad_therapy <dbl>, recurrence <dbl>, # censor <dbl>, time_to_recurrence <dbl> ``` ] --- count: false Example 4/6: Filter Preoperative PSA for Values within 1.5 units of 17 .panel1-filter4-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns * select(age, recurrence, preop_psa) ``` ] .panel2-filter4-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 72.1 1 14.1 2 73.6 1 10.5 3 67.5 0 6.98 4 65.8 0 4.4 5 63.2 0 21.4 6 65.4 0 5.1 7 65.5 0 6.03 8 67.1 1 8.7 9 63.9 0 3.83 10 63 0 7.98 # … with 306 more rows ``` ] --- count: false Example 4/6: Filter Preoperative PSA for Values within 1.5 units of 17 .panel1-filter4-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% * filter(near(preop_psa, 17, tol = 1.5)) ``` ] .panel2-filter4-auto[ ``` [1] 316 ``` ``` # A tibble: 6 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 63.4 1 15.7 2 65 0 15.7 3 57.5 0 15.9 4 58.8 1 15.6 5 63.9 0 18 6 70.6 0 17 ``` ] --- count: false Example 4/6: Filter Preoperative PSA for Values within 1.5 units of 17 .panel1-filter4-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(near(preop_psa, 17, tol = 1.5)) # see how many rows now # # Format: *# filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter4-auto[ ``` [1] 316 ``` ``` # A tibble: 6 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 63.4 1 15.7 2 65 0 15.7 3 57.5 0 15.9 4 58.8 1 15.6 5 63.9 0 18 6 70.6 0 17 ``` ] --- count: false Example 4/6: Filter Preoperative PSA for Values within 1.5 units of 17 .panel1-filter4-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(near(preop_psa, 17, tol = 1.5)) # see how many rows now # # Format: # filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter4-auto[ ``` [1] 316 ``` ``` # A tibble: 6 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 63.4 1 15.7 2 65 0 15.7 3 57.5 0 15.9 4 58.8 1 15.6 5 63.9 0 18 6 70.6 0 17 ``` ] <style> .panel1-filter4-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-filter4-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-filter4-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false Example 5/6: Filter Preoperative PSA for Values between 10 and 13 .panel1-filter5-auto[ ```r # how many rows when you start *nrow(prostate) ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ] --- count: false Example 5/6: Filter Preoperative PSA for Values between 10 and 13 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) *prostate ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 20 rbc_age_group median_rbc_age age aa fam_hx p_vol t_vol t_stage b_gs <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 3 25 72.1 0 0 54 3 1 3 2 3 25 73.6 0 0 43.2 3 2 2 3 3 25 67.5 0 0 103. 1 1 3 4 2 15 65.8 0 0 46 1 1 1 5 2 15 63.2 0 0 60 2 1 2 6 3 25 65.4 0 0 45.9 2 1 1 7 3 25 65.5 1 0 42.6 2 1 1 8 1 10 67.1 0 0 40.7 3 1 1 9 1 10 63.9 0 0 45 2 1 1 10 2 15 63 1 0 67.6 2 1 2 # … with 306 more rows, and 11 more variables: bn <dbl>, organ_confined <dbl>, # preop_psa <dbl>, preop_therapy <dbl>, units <dbl>, s_gs <dbl>, # any_adj_therapy <dbl>, adj_rad_therapy <dbl>, recurrence <dbl>, # censor <dbl>, time_to_recurrence <dbl> ``` ] --- count: false Example 5/6: Filter Preoperative PSA for Values between 10 and 13 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns * select(age, recurrence, preop_psa) ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 72.1 1 14.1 2 73.6 1 10.5 3 67.5 0 6.98 4 65.8 0 4.4 5 63.2 0 21.4 6 65.4 0 5.1 7 65.5 0 6.03 8 67.1 1 8.7 9 63.9 0 3.83 10 63 0 7.98 # … with 306 more rows ``` ] --- count: false Example 5/6: Filter Preoperative PSA for Values between 10 and 13 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% * filter(between(preop_psa, 10, 13)) ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 24 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 73.6 1 10.5 2 59.7 0 10.4 3 72.1 1 10.1 4 55.8 0 10 5 57.1 0 10 6 70.6 0 11.9 7 55.6 0 11.9 8 71.8 1 11.9 9 50.6 0 11.1 10 63.9 1 10.1 # … with 14 more rows ``` ] --- count: false Example 5/6: Filter Preoperative PSA for Values between 10 and 13 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(between(preop_psa, 10, 13)) # see how many rows now # # Format: *# filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 24 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 73.6 1 10.5 2 59.7 0 10.4 3 72.1 1 10.1 4 55.8 0 10 5 57.1 0 10 6 70.6 0 11.9 7 55.6 0 11.9 8 71.8 1 11.9 9 50.6 0 11.1 10 63.9 1 10.1 # … with 14 more rows ``` ] --- count: false Example 5/6: Filter Preoperative PSA for Values between 10 and 13 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(between(preop_psa, 10, 13)) # see how many rows now # # Format: # filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 24 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 73.6 1 10.5 2 59.7 0 10.4 3 72.1 1 10.1 4 55.8 0 10 5 57.1 0 10 6 70.6 0 11.9 7 55.6 0 11.9 8 71.8 1 11.9 9 50.6 0 11.1 10 63.9 1 10.1 # … with 14 more rows ``` ] <style> .panel1-filter5-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-filter5-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-filter5-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false Example 6/6: Filter Preoperative PSA for Values of 10 or 13 or 17 .panel1-filter5-auto[ ```r # how many rows when you start *nrow(prostate) ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ] --- count: false Example 6/6: Filter Preoperative PSA for Values of 10 or 13 or 17 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) *prostate ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 20 rbc_age_group median_rbc_age age aa fam_hx p_vol t_vol t_stage b_gs <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 3 25 72.1 0 0 54 3 1 3 2 3 25 73.6 0 0 43.2 3 2 2 3 3 25 67.5 0 0 103. 1 1 3 4 2 15 65.8 0 0 46 1 1 1 5 2 15 63.2 0 0 60 2 1 2 6 3 25 65.4 0 0 45.9 2 1 1 7 3 25 65.5 1 0 42.6 2 1 1 8 1 10 67.1 0 0 40.7 3 1 1 9 1 10 63.9 0 0 45 2 1 1 10 2 15 63 1 0 67.6 2 1 2 # … with 306 more rows, and 11 more variables: bn <dbl>, organ_confined <dbl>, # preop_psa <dbl>, preop_therapy <dbl>, units <dbl>, s_gs <dbl>, # any_adj_therapy <dbl>, adj_rad_therapy <dbl>, recurrence <dbl>, # censor <dbl>, time_to_recurrence <dbl> ``` ] --- count: false Example 6/6: Filter Preoperative PSA for Values of 10 or 13 or 17 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns * select(age, recurrence, preop_psa) ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 316 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 72.1 1 14.1 2 73.6 1 10.5 3 67.5 0 6.98 4 65.8 0 4.4 5 63.2 0 21.4 6 65.4 0 5.1 7 65.5 0 6.03 8 67.1 1 8.7 9 63.9 0 3.83 10 63 0 7.98 # … with 306 more rows ``` ] --- count: false Example 6/6: Filter Preoperative PSA for Values of 10 or 13 or 17 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% * filter(between(preop_psa, 10, 13)) ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 24 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 73.6 1 10.5 2 59.7 0 10.4 3 72.1 1 10.1 4 55.8 0 10 5 57.1 0 10 6 70.6 0 11.9 7 55.6 0 11.9 8 71.8 1 11.9 9 50.6 0 11.1 10 63.9 1 10.1 # … with 14 more rows ``` ] --- count: false Example 6/6: Filter Preoperative PSA for Values of 10 or 13 or 17 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(between(preop_psa, 10, 13)) # see how many rows now # # Format: *# filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 24 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 73.6 1 10.5 2 59.7 0 10.4 3 72.1 1 10.1 4 55.8 0 10 5 57.1 0 10 6 70.6 0 11.9 7 55.6 0 11.9 8 71.8 1 11.9 9 50.6 0 11.1 10 63.9 1 10.1 # … with 14 more rows ``` ] --- count: false Example 6/6: Filter Preoperative PSA for Values of 10 or 13 or 17 .panel1-filter5-auto[ ```r # how many rows when you start nrow(prostate) prostate %>% # check next line: some recur, some do not # selected 4 columns select(age, recurrence, preop_psa) %>% filter(between(preop_psa, 10, 13)) # see how many rows now # # Format: # filter(variable [comparison] value) <br> # filter(variable [comparison] value) <br> ``` ] .panel2-filter5-auto[ ``` [1] 316 ``` ``` # A tibble: 24 x 3 age recurrence preop_psa <dbl> <dbl> <dbl> 1 73.6 1 10.5 2 59.7 0 10.4 3 72.1 1 10.1 4 55.8 0 10 5 57.1 0 10 6 70.6 0 11.9 7 55.6 0 11.9 8 71.8 1 11.9 9 50.6 0 11.1 10 63.9 1 10.1 # … with 14 more rows ``` ] <style> .panel1-filter5-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-filter5-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-filter5-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: inverse, center # End of This Flipbook ## On to The Coding Exercises!