In this exercise we will start by looking at the characteristics of our dataset. All definitions and data come from the original Udacity lesson and can be found here.

Data

We start by assigning our data to Petals, a list of petal counts from flowers.

Petals <- c(15, 16, 17,
            16, 21, 22,
            15, 16, 15,
            17, 16, 22,
            14, 13, 14,
            14, 15, 15,
            14, 15, 16,
            10, 19, 15,
            15, 22, 24,
            25, 15, 16)

Frequency

The frequency of a data set is the number of times a certain outcome occurs.

# Find the most frequent petal count.
# to do this we create a table from Petals, sort it in decreasing order, and get the name of the first item.

MostFreq <- names(sort(table(Petals),decreasing=TRUE)[1])
print(paste0("The most frequent petal count is: ", MostFreq))
## [1] "The most frequent petal count is: 15"
# Find the frequency of flowers with 15 petals.
# We can use the same method as above but without the names
PetalFreq <- sort(table(Petals),decreasing=TRUE)[1]
print(paste0("The frequency of flowers with 15 petals is: ", PetalFreq))
## [1] "The frequency of flowers with 15 petals is: 9"

Proportions

A proportion is the fraction of counts over the total sample.

# Find the proportion of flowers with 15 petals

TotalSample <- length(Petals)
PetalProp <- PetalFreq/TotalSample
print(paste0("The proportion of flowers with 15 petals is: ", PetalProp))
## [1] "The proportion of flowers with 15 petals is: 0.3"

Percentage

A proportion can be turned into a percentage by multiplying the proportion by 100.

# Find the percentage of flowers with 15 petals

PetalPerc <- PetalProp * 100
print(paste0("The percentage of flowers with 15 petals is: ", PetalPerc, "%"))
## [1] "The percentage of flowers with 15 petals is: 30%"

Histogram

A histogram is a graphical representation of the distribution of data, discrete intervals (bins) are decided upon to form widths for our boxes. R has the hist() function to make basic histograms. Here are some very simple examples.

# Create a histogram with a bin size of 2
hist(Petals, breaks = (length(Petals)/2), col = "blue")

# Create a histogram with a bin size of 5
bins <- c(10,15,20,25,30)
#hist(Petals, breaks = (length(Petals)/5))
hist(Petals, breaks = bins, col = "orange")

Skew

Positive Skew - A positive skew is when outliers are present along the right most end of the distribution. The histogram for Petals is an example of a positive skew

Negative Skew - A negative skew is when outliers are present along the left most end of the distribution