# script for topic 7p # # to work with percentiles we need a significantly # large set of values. source("../gnrnd5.R") gnrnd5(41583023104, 31000444) L1 L2 <- sort(L1) L2 # to find the 41st percentile, find the index # that is at 0.41*(number of items in the data) 0.41*232 # then look round up and look at that item L2[ 96 ] # to find the 95th percentile, find the index # that is at 0.95*(number of items in the data) 0.95*232 # then look round up and look at that item L2[ 221 ] # to find the 43rd percentile, find the index # that is at 0.43*(number of items in the data) 0.43*232 # then look round up and look at that item L2[ 100 ] # R provides a function to get percentiles from our # data, without even sorting the data. This is the # quantile function. # Re-do the problems quantile(L1, 0.41) quantile(L1, 0.95) quantile(L1, 0.43) # this gives us a different answer # let us see if we can get some info on this ?quantile # and we can give quantile() a whole list of # percentiles to find quantile( L1, c(0.20, 0.33, 0.14, 0.78)) # or even a sequence of values quantile( L1, seq(0.60,0.95,0.05)) # If we want to know what percentile is the value # 487 we find 487 in the sorted data and then get # its position which( L2==487) # then find the percent that index is of the # total size of the data and then round down, # but we never go over 99% 213/232*100 #