0

help me figure out how to Merge these two date sets using R, I need to combine with the condition that the price of the car must be equal to the budget or lower from the declared budget up to 30%

UserBudget <- data.frame(user = c("Jon", "Bill", "Maria", "Ben", "Tina"),
                         budget = c(5000, 10000, 20000, 40000, 60000))

AutoMarket <- data.frame(
    car = c("Toyota Corolla (2000)", "Ford Focus (2002)", "Hyundai Elantra (2012)", 
            "Kia Forte (2014)", "Mercedes-Benz c250 (2014)","BMW 320I (2016)",
            "Tesla 3 (2018)", "Audi A6 (2019)", "Porsche Macan S (2019)", 
            "Mercedes-Benz c63 AMG (2017)", "Lexus RX 450L (2020)","BMW 740 (2020)","JAGUAR I-Place (2019)"),
    price = c(2500, 5000, 9900, 9999, 18500, 20000, 37000, 41000, 50000, 54000,55000,59000,60000)
)

The ideal result looks like this:

HappyDriver <- data.frame(
  user = c("Jon", "Bill","Bill", "Maria", "Maria","Ben","Tina","Tina","Tina","Tina","Tina"),
  budget = c(5000,10000,10000,20000,20000,40000,60000,60000,60000,60000,60000),
  car = c("Ford Focus (2002)","Hyundai Elantra (2012)", "Kia Forte (2014)","Mercedes-Benz c250 (2014)","BMW 320I (2016)","Tesla 3 (2018)",
          "Porsche Macan S (2019)", "Mercedes-Benz c63 AMG (2017)", "Lexus RX 450L (2020)","BMW 740 (2020)","JAGUAR I-Place (2019)"),
  price =c(5000,9900, 9999, 18500, 20000, 37000,50000, 54000,55000,59000,60000)
)
Henrik
  • 65,555
  • 14
  • 143
  • 159
Arty Art
  • 9
  • 1
  • or the `fuzzyjoin` package – r2evans Jan 06 '23 at 20:56
  • I'll un-dupe-hammer this since it appears some feel targeted that I closed it. But for reference, this is a dupe of https://stackoverflow.com/q/64362881/3358272, https://stackoverflow.com/q/64539945/3358272. – r2evans Jan 06 '23 at 21:05
  • 2
    The OP has not demonstrated any effort to complete a school assignment. The OP simply posted the given data and posted the expected results. The purpose of this website is to assist those who have put individual effort into achieving desired coding outcomes. – Gray Jan 07 '23 at 04:53

0 Answers0