In: Computer Science
R-Studio (R Programming Language)
4. 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 1) 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 difference between the largest and smallest values of
x. (This is the range. You can use `max` and
`min` or guess a built in command.)
```{r}
#insert your code
```
# create vector
x <- c(1, 8, 2, 6, 3, 8, 5, 5, 5, 5)
#1.`(X1 + X2 + . . .+ X10)/10` (use sum)
avg<-sum(x)/10
avg
# 2. Find log10(Xi) for each i. (Use the log function which by
default is base e)
for (X in x){
print(log10(X))
}
#3. Find `(Xi - 4.4)/2.875` for each i. (Do it all at once)
for (X in x){
print((X - 4.4)/2.875)
}
#4. Find the difference between the largest and smallest values of
x.
diff <- max(x) - min(x)
diff
/*OUTPUT */
/* PLEASE UPVOTE */