please use Rstudio to do this question. == == You have a sample of...

90.2K

Verified Solution

Question

Accounting

imageplease use Rstudio to do this question.

== == You have a sample of customers, some of whom have seen your ad ($ad T),and some have not seen your ad ($ad = F). In the data, we also record the customer ID ($id), her income ($inc), and her expenditure ($expd). For each customer who has seen the ad, find the customer who is closest in income among those who have not seen the ad, then calculate the difference in expenditure between these two customers. id inc expd ## ad 10 ##1 1 29.3 30 TRUE ## 2 2 29.6 25 FALSE ## 3 3 24.1 TRUE ## 4 4 27.2 15 TRUE ## 5 5 27.8 5 FALSE ## 6 6 35.6 30 FALSE For example, customer 1 ($id == 1) has seen the ad. Among the customers who have not seen the ad, customer 2 is closest in income. The expenditure difference between the two customers is 30- 25 = 5. Therefore, the result $expd.diff corresponding to customer 1 is 5. The same goes for customers 3 and 4. Shown below, your result should contain 3 numbers in $expd.diff. ## id expd.diff ## 1 1 5 ## 3 3 5 ## 4 4 10 Question: Write down your code that generates the given result, using either a repetition structure(for or while) or an apply- class function. Keep your code general enough so that one can use it on samples that are larger than 6 observations. [10

Answer & Explanation Solved by verified expert
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students