I am analyzing the student test data, but before that I want to tidy it. I tried to build a tidy data frame but it seems like the rows are duplicating. Below is my code.
library(tidyverse)
(Test <- tibble(
Student = c("A", "B", "C", "D", "E"),
Test1 = c("SAT", "SAT", "SAT", "SAT", "SAT"),
Test2 = c("NA", "ACT", "ACT", "ACT", "ACT"),
testdate1 = c("7/1/2017", "6/1/2017", "3/1/2017", "2/17/2018", "NA"),
testdate2 = c("NA", "NA", "1/1/2016", "12/1/2016", "10/1/2016")
))
(Testa <- tibble(
Student = c("A", "B", "C", "D", "E"),
Test1 = c("SAT", "SAT", "SAT", "SAT", "SAT"),
Test2 = c("NA", "ACT", "ACT", "ACT", "ACT")
))
(Testb <- tibble(
Student = c("A", "B", "C", "D", "E"),
testdate1 = c("7/1/2017", "6/1/2017", "3/1/2017", "2/17/2018", "NA"),
testdate2 = c("NA", "NA", "1/1/2016", "12/1/2016", "10/1/2016")
))
(td1 <- Testa %>%
gather(Test1, Test2, key = "Test", value = "Score"))
(td2 <- Testb %>%
gather(testdate1, testdate2, key = "Dated", value = "Datev"))
(tidy <- left_join(td1, td2))
Can anyone please help me solve this issue. Below is the image of how I want to see the data.