Skip to content

Commit

Permalink
Investigating...
Browse files Browse the repository at this point in the history
Added VEH1060 data, added some investigation, changed to latest available year of final data that I could manage to download.
  • Loading branch information
wengraf committed Feb 1, 2021
1 parent 6368439 commit 5c28f22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions R/carmatch.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# single place for functions (for now)
cm_get = function(u = "https://www.eea.europa.eu/data-and-maps/data/co2-cars-emission-18/co2-emissions-cars-2017-provisional/co2_passengers_cars_v15_csv/at_download/file", dir = tempdir()) {
cm_get = function(u = "https://www.eea.europa.eu/data-and-maps/data/co2-cars-emission-18/co2-emissions-cars-2017-final/co2_passengers_cars_v16_csv.zip/at_download/file", dir = tempdir()) {
f = file.path(dir, "co2.zip")
dd = file.path(dir, "co2")
if(!file.exists(f)) {
Expand Down Expand Up @@ -79,6 +79,36 @@ d_raw = cm_get()
system.time(saveRDS(d_raw, "d_raw_euco2.Rds"))
# 35s on fast computer! 40 MB

summary(as.factor(d_raw$Fuel_type))
library(readxl)
sheet1 <- read_excel("veh0160.xlsx", sheet = 1)
rownumber <- which(sheet1$`Department for Transport statistics` == "Make")
headers <- as.list(sheet1[rownumber,])
sheet1 <- sheet1[-c(1:(rownumber)),]
colnames(sheet1) <- headers
rm(headers)
rownumber <- which(sheet1$Make == "1. Entries containing \"MISSING\" or \"UNKNOWN MODEL\" are either for vehicles that have never been allocated a model code (most likely older vehicles manufactured before 1972) or new vehicles when the code lookup has not yet been published.")
sheet1 <- sheet1[-c(rownumber:nrow(sheet1)),]
sheet1 <- subset(sheet1, !(is.na(sheet1$Make)))

sheet1$UK2017 <- as.numeric(sheet1$`2017 Q1 UK`) +
as.numeric(sheet1$`2017 Q2 UK`) +
as.numeric(sheet1$`2017 Q3 UK`) +
as.numeric(sheet1$`2017 Q4 UK`)

UK2017 <- as.data.frame(cbind(sheet1$Make, sheet1$`Model 1`, sheet1$UK2017))
colnames(UK2017) <- c("Make", "DVLAModel", "2017 Registrations")
UK2017 <- subset(UK2017, !is.na(UK2017$`2017 Registrations`))

EU_GB <- subset(d_raw, d_raw$Country == "GB")

library(tidyverse)
EU_data_summary <- EU_GB %>% group_by(Manufacturer_name_MS,Commercial_name, NEDC_CO2, Mass_kg, Wheelbase, SteeringAxle, OtherAxle, Fuel_type, Engine_capacity) %>% dplyr::summarise("freq in EU data for UK" = n())

EU_data_summary$Commercial_name_in_VEH0160_2017 <- NA
EU_data_summary$Commercial_name_in_VEH0160 <- NA
UK2017$MakeModel <- paste0(UK2017$Make, " ", UK2017$DVLAModel)
EU_data_summary$MakeModel <- paste0(EU_data_summary$Manufacturer_name_MS, " ", EU_data_summary$Commercial_name)
sheet1$MakeModel <- paste0(sheet1$Make, " ", sheet1$`Model 1`)

EU_data_summary$Commercial_name_in_VEH0160_2017[EU_data_summary$MakeModel %in% UK2017$MakeModel] <- TRUE
EU_data_summary$Commercial_name_in_VEH0160[EU_data_summary$MakeModel %in% sheet1$MakeModel] <- TRUE
Binary file added veh0160.xlsx
Binary file not shown.

0 comments on commit 5c28f22

Please sign in to comment.