Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please use Rstudio to do this question. == == You have a sample of customers, some of whom have seen your ad ($ad T),and some
please 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. [10Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started