I want to extract the data for India and along the years from this world bank data on co2 emissions. How can I do that using R code for reproducible research?
https://api.worldbank.org/v2/en/indicator/EN.ATM.CO2E.KT?downloadformat=excel
Thanks for your support.
CodePudding user response:
This should most likely do what you want...
df = rio::import("API_EN.ATM.CO2E.KT_DS2_en_excel_v2_3469351.xls", which = 1)
df = df[5:270,] # hard code the length
df = df %>% filter(`Data Source` == "India")
CodePudding user response:
You can use the {readxl} package and specify the sheet and range to read:
library(dplyr)
library(readxl)
# Read in the data:
world_bank_data <- readxl::read_xls(
path = "world-bank-data.xls",
sheet = 1,
range = "A4:BK270"
)
# Filter rows where country name is India:
india <- world_bank_data |>
filter(`Country Name` == "India")
