2.6 Let the data x be given by > x = c(1, 8, 2, 6, 3, 8, 5, 5, 5, 5) Use R to co
ID: 3273401 • Letter: 2
Question
2.6 Let the data x be given by
> x = c(1, 8, 2, 6, 3, 8, 5, 5, 5, 5)
Use R to compute the following functions. Note, we use X1 to denote the first element of x (which is 0) etc.
1. (X1 + X2 + ... + X10 )= 10 (use sum )
2. Find log10 (Xi ) for each i . (Use the log function which by default is base e )
3. Find (Xi - 4: 4)/2: 875 for each i . (Do it all at once)
4. Find the dierence between the largest and smallest values of x . (This is the range. You can use max and min or guess a built in command.)
Explanation / Answer
The R commands are made bold for your reference.
Inputting the array:
> x = c(1, 8, 2, 6, 3, 8, 5, 5, 5, 5)
a) Finding the sum:
> sum(x)
[1] 48
b) Finding the Log(x) value:
> log10(x)
[1] 0.0000000 0.9030900 0.3010300 0.7781513 0.4771213 0.9030900 0.6989700 0.6989700
[9] 0.6989700 0.6989700
c) Here the loop was run as:
> for(i in x)
+ print( (i - 4: 4)/2: 875)
d) Range is computed as:
> max(x) - min(x)
[1] 7
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.