Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
6.6 kB
5
Indexable
Never
```{r Converting variable names of YD into name_year}

# Variables vector with dataset yd
variables <- c(
  "q1_4", "q2_4", "q3_4", "q4_4", "q5_4", "q6_4", "q7_4", "q8_4", "q9_4", "q10_4", "q11_4", "q12_4", "q13_4", "q14_4", "q15_4", "q16_4", 
  "q1_5", "q2_5", "q3_5", "q4_5", "q5_5", "q6_5", "q7_5", "q8_5", "q9_5", "q10_5", "q11_5", "q12_5", "q13_5", "q14_5", "q15_5", "q16_5", 
  "q1_8", "q2_8", "q3_8", "q4_8", "q5_8", "q6_8", "q7_8", "q8_8", "q9_8", "q10_8", "q11_8", "q12_8", "q13_8", "q14_8", "q15_8", "q16_8", 
  "q1_9", "q2_9", "q3_9", "q4_9", "q5_9", "q6_9", "q7_9", "q8_9", "q9_9", "q10_9", "q11_9", "q12_9", "q13_9", "q14_9", "q15_9", "q16_9", 
  "q1_11", "q2_11", "q3_11", "q4_11", "q5_11", "q6_11", "q7_11", "q8_11", "q9_11", "q10_11", "q11_11", "q12_11", "q13_11", "q14_11", "q15_11", "q16_11"
)

# Temporal data frame with variables
yd <- data.frame(matrix(ncol = length(variables), nrow = 1))
colnames(yd) <- variables

# Rename variables so they are in the structure "name_year"
yd <- yd |> 
  rename_with(~ str_replace_all(.,
                                c("^q1_4$" = "UrbanPopulation_1858", 
                                  "^q2_4$" = "UrbanPopulation_1868", 
                                  "^q3_4$" = "UrbanPopulation_1878", 
                                  "^q4_4$" = "UrbanPopulation_1888", 
                                  "^q5_4$" = "UrbanPopulation_1898", 
                                  "^q6_4$" = "UrbanPopulation_1908", 
                                  "^q7_4$" = "UrbanPopulation_1918", 
                                  "^q8_4$" = "UrbanPopulation_1928", 
                                  "^q9_4$" = "UrbanPopulation_1938", 
                                  "^q10_4$" = "UrbanPopulation_1948",
                                  "^q11_4$" = "UrbanPopulation_1958",
                                  "^q12_4$" = "UrbanPopulation_1968",
                                  "^q13_4$" = "UrbanPopulation_1978",
                                  "^q14_4$" = "UrbanPopulation_1988",
                                  "^q15_4$" = "UrbanPopulation_1998",
                                  "^q16_4$" = "UrbanPopulation_2000",
                                  "^q1_5$" = "NonAgriculturalPopulation_1858",
                                  "^q2_5$" = "NonAgriculturalPopulation_1868",
                                  "^q3_5$" = "NonAgriculturalPopulation_1878",
                                  "^q4_5$" = "NonAgriculturalPopulation_1888",
                                  "^q5_5$" = "NonAgriculturalPopulation_1898",
                                  "^q6_5$" = "NonAgriculturalPopulation_1908",
                                  "^q7_5$" = "NonAgriculturalPopulation_1918",
                                  "^q8_5$" = "NonAgriculturalPopulation_1928",
                                  "^q9_5$" = "NonAgriculturalPopulation_1938",
                                  "^q10_5$" = "NonAgriculturalPopulation_1948", 
                                  "^q11_5$" = "NonAgriculturalPopulation_1958",
                                  "^q12_5$" = "NonAgriculturalPopulation_1968",
                                  "^q13_5$" = "NonAgriculturalPopulation_1978",
                                  "^q14_5$" = "NonAgriculturalPopulation_1988", 
                                  "^q15_5$" = "NonAgriculturalPopulation_1998",
                                  "^q16_5$" = "NonAgriculturalPopulation_2000",
                                  "^q1_8$" = "Students_1858", 
                                  "^q2_8$" = "Students_1868", 
                                  "^q3_8$" = "Students_1878", 
                                  "^q4_8$" = "Students_1888", 
                                  "^q5_8$" = "Students_1898", 
                                  "^q6_8$" = "Students_1908", 
                                  "^q7_8$" = "Students_1918", 
                                  "^q8_8$" = "Students_1928", 
                                  "^q9_8$" = "Students_1938", 
                                  "^q10_8$" = "Students_1948", 
                                  "^q11_8$" = "Students_1958", 
                                  "^q12_8$" = "Students_1968", 
                                  "^q13_8$" = "Students_1978", 
                                  "^q14_8$" = "Students_1988", 
                                  "^q15_8$" = "Students_1998", 
                                  "^q16_8$" = "Students_2000",
                                  "^q1_9$" = "Literacy_1858", 
                                  "^q2_9$" = "Literacy_1868",
                                  "^q3_9$" = "Literacy_1878", 
                                  "^q4_9$" = "Literacy_1888",
                                  "^q5_9$" = "Literacy_1898", 
                                  "^q6_9$" = "Literacy_1908", 
                                  "^q7_9$" = "Literacy_1918", 
                                  "^q8_9$" = "Literacy_1928",
                                  "^q9_9$" = "Literacy_1938",
                                  "^q10_9$" = "Literacy_1948",
                                  "^q11_9$" = "Literacy_1958", 
                                  "^q12_9$" = "Literacy_1968", 
                                  "^q13_9$" = "Literacy_1978", 
                                  "^q14_9$" = "Literacy_1988", 
                                  "^q15_9$" = "Literacy_1998", 
                                  "^q16_9$" = "Literacy_2000",
                                  "^q1_11$" = "FamilyFarms_1858", 
                                  "^q2_11$" = "FamilyFarms_1868", 
                                  "^q3_11$" = "FamilyFarms_1878", 
                                  "^q4_11$" = "FamilyFarms_1888", 
                                  "^q5_11$" = "FamilyFarms_1898",
                                  "^q6_11$" = "FamilyFarms_1908", 
                                  "^q7_11$" = "FamilyFarms_1918", 
                                  "^q8_11$" = "FamilyFarms_1928", 
                                  "^q9_11$" = "FamilyFarms_1938", 
                                  "^q10_11$" = "FamilyFarms_1948", 
                                  "^q11_11$" = "FamilyFarms_1958", 
                                  "^q12_11$" = "FamilyFarms_1968",
                                  "^q13_11$" = "FamilyFarms_1978",
                                  "^q14_11$" = "FamilyFarms_1988",
                                  "^q15_11$" = "FamilyFarms_1998", 
                                  "^q16_11$" = "FamilyFarms_2000"
                                          )))

```
Leave a Comment