2.1 Suppose you keep track of your mileage each time you fill up. At your last 6
ID: 3273053 • Letter: 2
Question
2.1 Suppose you keep track of your mileage each time you fill up. At your last 6 fill-ups the mileage was
65311 65624 65908 66219 66499 66821 67145 67447
Enter these numbers into R . Use the function diff on the data. What does it give?
> miles = c(65311, 65624, 65908, 66219, 66499, 66821, 67145, 67447)
> x = diff(miles)
You should see the number of miles between fill-ups. Use the max to nd the maximum number of miles between fill-ups, the mean function to find the average number of miles and the min to get the minimum number of miles.
Explanation / Answer
Note that the R commands are in bold in this solution.
The given functions were inputted to generate an array of consecutive differences of the miles.
> miles = c(65311, 65624, 65908, 66219, 66499, 66821, 67145, 67447)
> x = diff(miles)
Now the maximum number of miles between fill ups is computed as:
> max(x)
[1] 324
Now the average number of miles between fill ups is computed as:
> mean(x)
[1] 305.1429
Now the minimum number of miles between fill ups is computed as:
> min(x)
[1] 280
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.