mydata. <- read.csv("00_data/mydata.")
#I Do not think I can fill this out.
mydata_long <- mydata. %>%
pivot_longer(
cols = c(`Population.2025`, `Yearly.Change`, `Net.Change`),
names_to = "measure",
values_to = "value",
values_transform = list(
value = as.character))
head(mydata_long)
## # A tibble: 6 × 11
## id Country..or.dependency. Density..P.Km.. Land.Area..Km.. Migrants..net.
## <int> <chr> <int> <int> <chr>
## 1 1 India 492 2973190 −495,753
## 2 1 India 492 2973190 −495,753
## 3 1 India 492 2973190 −495,753
## 4 2 China 151 9388211 −268,126
## 5 2 China 151 9388211 −268,126
## 6 2 China 151 9388211 −268,126
## # ℹ 6 more variables: Fert..Rate <dbl>, Median.Age <dbl>, Urban.Pop.. <chr>,
## # World.Share <chr>, measure <chr>, value <chr>
mydata_sep <- mydata. %>%
separate(col = Fert..Rate, into = c("whole.Fret#", "Decimal#"), convert = TRUE )
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 4 rows [40, 59, 222,
## 233].
head(mydata_sep)
## id Country..or.dependency. Population.2025 Yearly.Change Net.Change
## 1 1 India 1463865525 0.89% 12929734
## 2 2 China 1416096094 −0.23% −3,225,184
## 3 3 United States 347275807 0.54% 1849236
## 4 4 Indonesia 285721236 0.79% 2233305
## 5 5 Pakistan 255219554 1.57% 3950390
## 6 6 Nigeria 237527782 2.08% 4848304
## Density..P.Km.. Land.Area..Km.. Migrants..net. whole.Fret# Decimal#
## 1 492 2973190 −495,753 1 94
## 2 151 9388211 −268,126 1 2
## 3 38 9147420 1230663 1 62
## 4 158 1811570 −39,509 2 1
## 5 331 770880 −1,235,336 3 5
## 6 261 910770 −15,258 4 3
## Median.Age Urban.Pop.. World.Share
## 1 28.8 37.1% 17.78%
## 2 40.1 67.5% 17.20%
## 3 38.5 82.8% 4.22%
## 4 30.4 59.6% 3.47%
## 5 20.6 34.4% 3.10%
## 6 18.1 54.9% 2.89%
mydata_united <- mydata. %>%
unite(col = "Population.2025","World.Share",
sep = "_",
remove = TRUE
)
head(mydata_united)
## id Country..or.dependency. Yearly.Change Net.Change Density..P.Km..
## 1 1 India 0.89% 12929734 492
## 2 2 China −0.23% −3,225,184 151
## 3 3 United States 0.54% 1849236 38
## 4 4 Indonesia 0.79% 2233305 158
## 5 5 Pakistan 1.57% 3950390 331
## 6 6 Nigeria 2.08% 4848304 261
## Land.Area..Km.. Migrants..net. Fert..Rate Median.Age Urban.Pop..
## 1 2973190 −495,753 1.94 28.8 37.1%
## 2 9388211 −268,126 1.02 40.1 67.5%
## 3 9147420 1230663 1.62 38.5 82.8%
## 4 1811570 −39,509 2.10 30.4 59.6%
## 5 770880 −1,235,336 3.50 20.6 34.4%
## 6 910770 −15,258 4.30 18.1 54.9%
## Population.2025
## 1 17.78%
## 2 17.20%
## 3 4.22%
## 4 3.47%
## 5 3.10%
## 6 2.89%
mydata. %>%
filter(Land.Area..Km.. == 0)
## id Country..or.dependency. Population.2025 Yearly.Change Net.Change
## 1 233 Holy See 501 1.01% 5
## Density..P.Km.. Land.Area..Km.. Migrants..net. Fert..Rate Median.Age
## 1 1253 0 13 1 57.4
## Urban.Pop.. World.Share
## 1 <NA> 0.0000061%
mydata_missing <- mydata. %>%
mutate(
Land.Area..Km.. = ifelse(Land.Area..Km.. == 0, NA, Land.Area..Km..))
colSums(is.na(mydata_missing))
## id Country..or.dependency. Population.2025
## 0 0 0
## Yearly.Change Net.Change Density..P.Km..
## 0 0 0
## Land.Area..Km.. Migrants..net. Fert..Rate
## 1 0 0
## Median.Age Urban.Pop.. World.Share
## 0 23 0