Hi.
I have data of students with various parameters. The student names are mentioned initially (with variable name "cal_name") and the responses given (as 0 or 1) in for parameters (given as q_1_1, q_1_2,.., etc.). q_1_1 till q_1_11 are the parameters for student1, q_2_1 till q_2_11 are for student2 and so on.
I have done written a code but this doesn't work for me as the final file is not as per my requirement. I need the data in the vertical format with the student names/ids and their responses to the parameters given. But here a large number of duplicates are formed. Can I solve this issue?
library(tidyverse)
data1<-tibble::tribble(
~schoolid, ~teacherid, ~cal_name1, ~cal_name2, ~cal_name3, ~cal_name4, ~cal_name5, ~q_1, ~q_1_1, ~q_1_2, ~q_1_3, ~q_1_4, ~q_1_5, ~q_1_6, ~q_1_7, ~q_1_8, ~q_1_9, ~q_1_10, ~q_1_11, ~q_2, ~q_2_1, ~q_2_2, ~q_2_3, ~q_2_4, ~q_2_5, ~q_2_6, ~q_2_7, ~q_2_8, ~q_2_9, ~q_2_10, ~q_2_11, ~q_3, ~q_3_1, ~q_3_2, ~q_3_3, ~q_3_4, ~q_3_5, ~q_3_6, ~q_3_7, ~q_3_8, ~q_3_9, ~q_3_10, ~q_3_11, ~q_4, ~q_4_1, ~q_4_2, ~q_4_3, ~q_4_4, ~q_4_5, ~q_4_6, ~q_4_7, ~q_4_8, ~q_4_9, ~q_4_10, ~q_4_11, ~q_5, ~q_5_1, ~q_5_2, ~q_5_3, ~q_5_4, ~q_5_5, ~q_5_6, ~q_5_7, ~q_5_8, ~q_5_9, ~q_5_10, ~q_5_11,
"DPEP Kusugal", "Manjula A", "Anand Byahatti-9AHCMX", "Apsana. S Hubballi-R0UQTS", "Fathima Begum.R.Kawalikai-ABUFRY", "Jyothi Byahatti-7I6QJM", "Momadsad Huggi-TFN2GP", "1 10", 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, "10", 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, "4 10", 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, "5 8", 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, "4", 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
"GHPS Giriyal", "B.M.Hosamani", "Netra S. Kattimani-FAU4EG", "Preeti Salagar-ALWZO7", "Shrikant Jadav-1LAF0L", NA, NA, "1 3 8 10 11", 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, "7 11", 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
"DPEP Kusugal", "Manjula A", "Anand Byahatti-9AHCMX", "Apsana. S Hubballi-R0UQTS", "Fathima Begum.R.Kawalikai-ABUFRY", "Jyothi Byahatti-7I6QJM", "Momadsad Huggi-TFN2GP", "3 6 9", 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, "4 7", 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, "3 9", 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, "5", 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, "7", 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
"GHPS Giriyal", "B.M.Hosamani", "Netra S. Kattimani-FAU4EG", "Preeti Salagar-ALWZO7", "Shrikant Jadav-1LAF0L", NA, NA, "3 4", 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
"GHPS Giriyal", "B.M.Hosamani", "Netra S. Kattimani-FAU4EG", "Preeti Salagar-ALWZO7", "Shrikant Jadav-1LAF0L", NA, NA, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, "3 9", 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
"DPEP Kusugal", "Manjula A", "Anand Byahatti-9AHCMX", "Apsana. S Hubballi-R0UQTS", "Fathima Begum.R.Kawalikai-ABUFRY", "Jyothi Byahatti-7I6QJM", "Momadsad Huggi-TFN2GP", "1 5 7", 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, "4 8", 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, "4 6 8 10", 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, "5 6", 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, "2 4 8 10", 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L
)
Students <- data1 |>
select(schoolid, starts_with("cal_name"))
Students <- Students |>
pivot_longer(cols = -schoolid,names_to = "ID",values_to = "Name") |>
mutate(ID=str_remove(ID,"cal_name")) |>
filter(!is.na(Name))
Scores <- data1 |>
select(schoolid,matches("q_\\d+_\\d+"))
Scores <- Scores |>
pivot_longer(cols = -schoolid,names_to = "ID",values_to = "Score") |>
mutate(Q=str_remove(ID,"_\\d+"),
ID=str_extract(ID,"\\d+")) |>
filter(!is.na(Score)) |>
pivot_wider(names_from = "Q",values_from = "Score")
#> Warning: Values are not uniquely identified; output will contain list-cols.
#> * Use `values_fn = list` to suppress this warning.
#> * Use `values_fn = length` to identify where the duplicates arise
#> * Use `values_fn = {summary_fun}` to summarise duplicates
Final1 <- inner_join(Students,Scores,by="schoolid")