These questions use R. 1. Enter the following values into a data vector named te
ID: 3310510 • Letter: T
Question
These questions use R.
1. Enter the following values into a data vector named testdata: 45.4 44.2 36.8 35.1 39.0 60.0 47.4 41.1 45.8 35.6 Calculate the difference between the 2nd and 7th entries of this vector using only reference indices. 2. 3. Calculate the median of testdata. . Sort the values in this data vector from highest to lowest, and save the sorted version as a 5. 6. 7. vector named sortHL.testdata. What does sortHLtestdata[-4] do? What does testdatal-c(2,7,9)] do? Why do you think the c() function necessary in the previous question?Explanation / Answer
> #1
> testdata=c(45.4,44.2,36.8,35.1,39,60,47.4,41.1,45.8,35.6)
> #2
> testdata[7]-testdata[2]
[1] 3.2
> #3
> median(testdata)
[1] 42.65
> #4
> sortHL.testdata=testdata[order(testdata,decreasing=TRUE)]
> sortHL.testdata
[1] 60.0 47.4 45.8 45.4 44.2 41.1 39.0 36.8 35.6 35.1
> #5
> sortHL.testdata[-4]
[1] 60.0 47.4 45.8 44.2 41.1 39.0 36.8 35.6 35.1
> #It delete's fourth element from the sortHL.testdata vector
> #6
> testdata[-c(2,7,9)]
[1] 45.4 36.8 35.1 39.0 60.0 41.1 35.6
> #It delete's 2nd, 7th and 9th element from testdata vector.
> #7
> #As we want to delete (or remove) more than one element simultaneously
> #we have to use c() function. c() denotes vector.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.