In: Computer Science
Using R: write a program that finds the standard deviation between each column. Find the average standard deviation for Set A and B, and then use that average to guess the next (fifth) column. Set A: 2, 5, 7, 8 Set B: 2, 3, 6, 9
In R, we need to comine the two vectors in a 2D vector using rbind. Then get the sd for each column.
Then calculate the average sd from the values.
Then in order to generate next column values, we require mean, and sd values for function rnorm().
For mean we get the trend of means from the given series and decide a mean that follows that progression.
Finally generate the next column:
CODE:
library(matrixStats)
A<- c(2, 5, 7, 8)
B<- c(2, 3, 6, 9)
C <- rbind(A,B)
#displaying C
C
#finding SDs per column
col_sd <- colSds(C)
col_sd
#getting average sd from col_sd
avg_sd = round(mean(col_sd))
avg_sd
#means of the columns to get next mean:
col_mean <- colMeans(C)
col_mean
#taking mean as 11 for next numbers and sd as avg_sd:
next_col <- ceiling(rnorm(2,mean=11,sd=avg_sd))
next_col
OUTPUT: