I have a dataset where I track teachers week-wise. There are specific goals which have to be achieved. The goals are arranged week-wise. Hence, goal 1 is for week 1, goal 2 is for week 2 and so on. I want to convert the data so that a new variable "goal" is created and only the relevant score is shown (as can be seen in "data2" in the reprex).
library(tidyverse)
data<-tibble::tribble(
~master, ~schoolid, ~teacher, ~week_no, ~goal1, ~goal2,
"Nagma", "GHPS UNKAL", "Gandhi", 1L, 1L, NA,
"Anil", "GLPS REVADIHAL", "Nehru", 1L, 1L, NA,
"Anil", "GLPS CHIKKAMTH", "Obama", 1L, 2L, NA,
"Madhumathi", "GHPS NO.3 KANNADA", "Gerald", 1L, 1L, NA,
"Nagma", "GHPS PALE", "Gandhi", 2L, NA, 1L,
"Anil", "GHPS INAM", "Nehru", 2L, NA, 2L,
"Anil", "GLPS BYAHATTI", "Obama", 2L, NA, 1L,
"Madhumathi", "GHPS KIRESUR", "Gerald", 2L, NA, 1L
)
data2<-tibble::tribble(
~master, ~schoolid, ~teacher, ~week_no, ~goal, ~goal1, ~goal2,
"Nagma", "GHPS UNKAL", "Gandhi", 1L, "goal1", 1L, NA,
"Anil", "GLPS REVADIHAL", "Nehru", 1L, "goal1", 1L, NA,
"Anil", "GLPS CHIKKAMTH", "Obama", 1L, "goal1", 2L, NA,
"Madhumathi", "GHPS NO.3 KANNADA", "Gerald", 1L, "goal1", 1L, NA,
"Nagma", "GHPS PALE", "Gandhi", 2L, "goal2", NA, 1L,
"Anil", "GHPS INAM", "Nehru", 2L, "goal2", NA, 2L,
"Anil", "GLPS BYAHATTI", "Obama", 2L, "goal2", NA, 1L,
"Madhumathi", "GHPS KIRESUR", "Gerald", 2L, "goal2", NA, 1L
)
Created on 2022-09-30 by the reprex package (v2.0.1)