I would like to ask how to reshape the following dataframe from wide-type to long-type. The wide-type data is as follows.
Wide-type data before reshaping:
The long type data, i.e. the dataframe that I would like to get, is as follows.
Long-type data after reshaping:
Hugely appreciate if you could give me tips to do this using pivot-longer. I could reshape the data separately by BLS and ELS by writing:
df_long_BLS <- df %>%
pivot_longer(
cols = starts_with("BLS_tchrG"),
names_to = "grade",
names_prefix = "BLS_tchrG",
values_to = "BLS_tchrG"
)
df_long_ELS <- df %>%
pivot_longer(
cols = starts_with("ELS_tchrG"),
names_to = "grade",
names_prefix = "ELS_tchrG",
values_to = "ELS_tchrG"
)
But in this way I need to merge the 2 separate files. I would like to know how to do this data reshape without making 2 separate files.