Here I am giving a survey dataset, where the response is recorded. I want a column to come beside which shows the score.
library(tidyverse)
library(janitor)
#>
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#>
#> chisq.test, fisher.test
nithin<-tibble::tribble(
~enumerator, ~l1c1, ~l1c2, ~l1c3, ~l1c4,
"PEN001", 1L, -99L, 1L, 1L,
"PEN002", 0L, 0L, 0L, 1L,
"PEN001", -99L, 0L, 1L, 0L,
"PEN001", 1L, 0L, -99L, 1L
)
The wanted result will come like this:
nithin2<-tibble::tribble(
~enumerator, ~l1c1, ~q1_score, ~l1c2, ~q2_score, ~l1c3, ~q3_score, ~l1c4, ~q4_score,
"PEN001", 1L, 2L, -99L, 0L, 1L, 2L, 1L, 2L,
"PEN002", 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L,
"PEN001", -99L, 0L, 0L, 0L, 1L, 2L, 0L, 0L,
"PEN001", 1L, 2L, 0L, 0L, -99L, 0L, 1L, 2L
)