My script currently is very messy and I was wondering if there is a better way of doing this;
I am trying to workout the final price of a product. This is the steps I take;
Dataset A has all the products which changes every year, Dataset B has the base price for the products which also changes every year.
- In Dataset A, find the product base price by matching the product in Dataset B.
- In Dataset A, apply numerous variations to the base price, these adjustments change every year. I am currently manually putting in the variations.
- After the variations, this is my final price.
Dataset A has columns product. Dataset B has columns product and base.price.
Variation 1 = base price needs to be adjusted by 10% if it meets a condition. Variation 2 = after variation 1, base price adjusted to be 5% if it meets a condition. Variation 3 = after variation 1 and 2, base price to be adjusted by 8% if its meets a condition.
library(tidyverse)
####creating sample database
product <- c("pants", "shirt", "boots", "dress")
databaseA<-data.frame(product)
base.price <- c(10, 8, 9,16)
databaseB<-data.frame(product,base.price)
###
datasetAB<-dplyr::left_join(datasetA, datasetB, by = c("product"="product"))
#variation 1
datasetAB<-datasetAB%>%mutate(baseprice1=base.price*1.1)
#variation 2
datasetAB<-datasetAB%>%mutate(baseprice2=baseprice1*1.05)
#variation 3
datasetAB<-datasetAB%>%mutate(baseprice3=baseprice2*1.08)
I am trying to workout if there is a better way of doing this, instead of importing so many datasets and referencing all the different datasets in my code. Because it changes every year, there is just too much datasets.
I am sorry, I don't have enough reputations to show properly.