This code is good. But I came across a new issue now. Even where rows contain "98", the N98 variable does not show the exact number. In the reprex below, the last student has "98" values, but that is not shown in the N98 variable and the No.response.ratio is also showing NA.
library(tidyverse)
nithin<-tibble::tribble(
~Student, ~l1c1_identify_pic1, ~l1c1_identify_pic2, ~l1c1_identify_pic3, ~l1c1_identify_pic4, ~l1c1_identify_pic5, ~l1c1_identify_pic6, ~l1c1_classify_bird, ~l1c1_classify_animal, ~l1c1_identification, ~l1c1_classification, ~l1c1_total, ~l1c2_identify_col1, ~l1c2_identify_col2, ~l1c2_identify_col3, ~l1c2_sort_col1, ~l1c2_identify, ~l1c2_sort, ~l1c2_total, ~l1c3_identify_shape1, ~l1c3_identify_shape2, ~l1c3_identify_shape3, ~l1c3_sort_shape1, ~l1c3_identify, ~l1c3_sort, ~l1c3_total, ~l1c4_corr_card, ~l1c4_total, ~l1c5_card_order,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 12L, 2L, 14L, 1L, 0L, 1L, 1L, 1, 0.5, 1.5, 1L, 0L, 98L, 1L, 0.5, 0.5, 1, 0L, 0L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 12L, 2L, 14L, 98L, 98L, 1L, 1L, 0.5, 0.5, 1, 98L, 98L, 98L, 1L, 0, 0.5, 0.5, 0L, 0L, 1L,
3L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 10L, 1L, 11L, 0L, 1L, 1L, 1L, 1, 0.5, 1.5, 1L, 1L, 98L, 1L, 1, 0.5, 1.5, 2L, 2L, 0L,
4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 12L, 2L, 14L, 0L, 1L, 0L, 1L, 0.5, 0.5, 1, 1L, 1L, 0L, 1L, 1, 0.5, 1.5, 1L, 1L, 0L,
5L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 10L, 0L, 10L, 0L, 1L, 1L, 1L, 1, 0.5, 1.5, 0L, 0L, 0L, 1L, 0, 0.5, 0.5, 1L, 1L, 0L,
6L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 12L, 0L, 12L, 0L, 1L, 1L, 1L, 1, 0.5, 1.5, 1L, 0L, 0L, 1L, 0.5, 0.5, 1, 1L, 1L, 1L,
7L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 10L, 2L, 12L, 0L, 0L, 0L, 1L, 0, 0.5, 0.5, 0L, 0L, 0L, 1L, 0, 0.5, 0.5, 2L, 2L, 1L,
8L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 12L, 2L, 14L, 1L, 1L, 1L, 1L, 1.5, 0.5, 2, 1L, 1L, 1L, 1L, 1.5, 0.5, 2, 2L, 2L, 1L,
NA, 98L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 4L, 2L, 6L, 0L, 0L, 0L, 1L, 0, 0.5, 0.5, 98L, 98L, 98L, 1L, 0, 0.5, 0.5, 0L, 0L, 0L
)
nithin<-nithin %>%
rowwise() %>%
mutate(
N98=sum(across(where(is.numeric), ~.x==98)),
NDenom=sum(across(where(is.numeric), ~!is.na(.x))),
No.response.ratio=N98/NDenom
) %>%
ungroup()
nithin
#> # A tibble: 9 x 32
#> Student l1c1_identify_pic1 l1c1_identify_pi~ l1c1_identify_p~ l1c1_identify_p~
#> <int> <int> <int> <int> <int>
#> 1 1 1 1 1 1
#> 2 2 1 1 1 1
#> 3 3 1 1 0 1
#> 4 4 1 1 1 1
#> 5 5 1 1 1 1
#> 6 6 1 1 1 1
#> 7 7 1 1 0 1
#> 8 8 1 1 1 1
#> 9 NA 98 1 0 1
#> # ... with 27 more variables: l1c1_identify_pic5 <int>,
#> # l1c1_identify_pic6 <int>, l1c1_classify_bird <int>,
#> # l1c1_classify_animal <int>, l1c1_identification <int>,
#> # l1c1_classification <int>, l1c1_total <int>, l1c2_identify_col1 <int>,
#> # l1c2_identify_col2 <int>, l1c2_identify_col3 <int>, l1c2_sort_col1 <int>,
#> # l1c2_identify <dbl>, l1c2_sort <dbl>, l1c2_total <dbl>,
#> # l1c3_identify_shape1 <int>, l1c3_identify_shape2 <int>, ...
Created on 2021-11-03 by the reprex package (v2.0.1)