Case sensitive recoding

Hi,
I have this simple file where I recode find specific characters within the VIN string and recode then accordingly:

source <- data.frame(
  stringsAsFactors = FALSE,
                     URN = c(2012783636,
                             2012995395,2012995397,2012995454,2012995644,2012995693,
                             2012995725,2012995921,2013431,2013443,2013522,
                             2013599),
                      VIN = c("TMAJ2811ACJ774380",
                             "NLHA851CBLZ544242","TMAH281AALJ054938",
                             "TMAJ3811AJJ692256","KMHK3811AKU315664",
                             "KMHS381CDKU100986","TMAHC51AAKJ013639","kmhk3811aju174838",
                             "nlhb351bakz521795","kmhs381cdku036796",
                             "kmhs381cdku039749","nlhb351bakz530228")
      )

source


library(dplyr)
library(stringr)
Current.Sales.data <- source %>% 
  mutate(VINChar = substring(VIN, 4, 5),
         IONIQVINChar = substring(VIN, 8, 8),
         VINYear = substring(VIN, 10, 10))

library(car)
Current.Sales.data$Reg.Year <- recode(Current.Sales.data$VINYear,"1 =2001; 2 =2002; 3 =2003; 4 =2004; 5 =2005; 6 =2006; 7 =2007; 8 =2008; 9 =2009; 
'A' =2010; 'B' =2011; 'C' =2012; 'D' =2013; 'E' =2014; 'F' =2015; 'G' =2016; 'H' =2017; 
'J' =2018; 'K' =2019; 'L' =2020; 'M' =2021; 'N' =2022; 'Y' =2000; 
'a' =2010; 'b' =2011; 'c' =2012; 'd' =2013; 'e' =2014; 'f' =2015; 'g' =2016; 'h' =2017; 
'j' =2018; 'k' =2019; 'l' =2020; 'm' =2021; 'n' =2022;  'y' =2000")

Nevertheless I am repeating the same for upper and lower cases. Is any way of avoiding that?

VINYear = toupper(substring(VIN, 10, 10))

Excellent! Thank you :smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.