I'm working in R and have a data frame with test proficiency results by school and subject. Initially, there was a separate row for each test result, and a column telling what content area was tested. I want a single row per school, with a column for the proficiency % of each content area. Here is a sample of my data
structure(list(pct_proficient = c(NA, 55.36, 34.98, NA, NA, 50,
34.72, NA, NA, NA), school_year = c(2021, 2021, 2021, 2021, 2021,
2021, 2021, 2021, 2021, 2021), school_code = c(610, 610, 610,
611, 612, 612, 612, 615, 615, 615), content_area = c("CMP", "ELA",
"MATH", "CMP", "CMP", "ELA", "MATH", "ELA", "MATH", "ELA"), organization = c("Allen Frear Elementary School",
"Allen Frear Elementary School", "Allen Frear Elementary School",
"J. Ralph McIlvaine Early Childhood Center", "Major George S. Welch Elementary School",
"Major George S. Welch Elementary School", "Major George S. Welch Elementary School",
"Kent Elementary Intensive Learning Center", "Kent Elementary Intensive Learning Center",
"Kent Elementary Intensive Learning Center")), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
I used:
perf_wide <- Performance_by_school %>%
pivot_wider(names_from = content_area, values_from = pct_proficient)
This resulted in a data frame with the structure I wanted, but each entry is now a list including the proficiency and the value NA
. For example, one entry in the column MATH reads c(42.1, NA)
. How can I get rid of the NA
s and get a single value for each entry?