Write your own function that returns the 75th percentile of a vector. Apply this function to all columns of matrix b.
Here's matrix b:
b = matrix(runif(1000*18, min=1000, max=10000), 1000, 18)
And here's the function I've created using indexing.
percentileOfAVector <- function(vector,percentile){
adjustedVector=vector[0:floor(percentile * length(vector))]
return (adjustedVector)
}
I was wondering if I can use the apply function to adjust the b vector that I've got. Or should I use a for loop?
PS: I tried to do it with a for loop but I had some problems with cbind when I was trying to store the results of my function in a matrix.
Any help would be greatly appreciated.