# preprocessr
#
# Function: bucketize()
#
# Description: A function to discretize a set of continuous data
#
# Author: Peter Xenopoulos
#
#
bucketize <- function(data, buckets) {
if(class(data) != "numeric")
warning("Data must be a vector of type numeric")
# get # of bins, and length of data vector
bins = c(1:buckets)
data.len = length(data)
# find how many extra slots the last bucket will have
leftover = data.len %% buckets
# find the width of a bucket
width = floor(data.len/buckets)
# initialize vector to return
bucketized.vector <- ()
for(i in 1:data.len) {
bucketized.vector[i]
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.