I have this dataset GDP growth rate with year in GDP column
But I want to have a dataset like this using R GDP growth rate with year in separate column
CodePudding user response:
We may use pivot_longer
for that
library(tidyr)
library(dplyr)
pivot_longer(df1, cols = starts_with("GDP"), names_to = c(".value", "Year"),
names_pattern = "([^\\d ])(\\d )") %>%
rename(`Growth rate` = GDP_GR)
CodePudding user response:
Does this do what you want?
library(dpylr)
df <- df %>% arrange(Country name, Year)