---
title: "Solution / A.6.104"
author: Martin Schedlbauer
output: html_notebook
---

## Tasks

1.  Load the CSV file from the URL provided above into a data frame called *df.wines*. Do not load the text (strings) as factors. Check to see if the CSV contains column headers and load appropriately.

```{r loadData}
url <- "https://s3.us-east-2.amazonaws.com/artificium.us/datasets/whitewines.csv"
df.wines <- read.csv(url,
                     header = T,
                     stringsAsFactors = F)
```


2.  Inspect the data frame and determine its structure.

```{r inspectData}
head(df.wines, 4)
str(df.wines)
```


3.  How many wines have a residual sugar level above 0.5 and an alcohol level above 7?

```{r}
w <- which(df.wines$residual.sugar > 0.5 & df.wines$alcohol > 7)

n <- length(w)

print(n)
```


4.  How many wines have an alcohol content between 9.5 and 11.5 (exclusive) and a quality rating below 7?

```{r}
w <- which(df.wines$alcohol >= 9.5 & df.wines$alcohol <= 11.5 & df.wines$quality < 7)

n <- length(w)

print(n)
```

5.  Are there any wines with an alcohol content above 14?

```{r}
w <- which(df.wines$alcohol > 14)

n <- length(w)

print(n)
```

6.  What are the median and mean alcohol content of all wines?

```{r}
mean.alcohol <- mean(df.wines$alcohol)
median.alcohol <- median(df.wines$alcohol)
```


7.  Add a new column to the data frame *df.wines* called *swill_index* that is calculated by dividing the alcohol content by the the quality and multiplying it by the residual sugar content.

```{r}
df.wines$swill_index <- (df.wines$alcohol / df.wines$quality) * df.wines$residual.sugar
```


8.  Add a new column to the data frame *df.wines* called *alcohol.z* that calculates the *z*-score for alcohol. The *z*-score for a feature is calculated as the number of standard deviations that the value is from the mean. So, calculate the mean and the standard deviation for alcohol and then set the value of the *alcohol.z* column to the value to: *mean(alcohol) - alcohol] / sd(alcohol)*.

```{r}
sd.alcohol <- sd(df.wines$alcohol)
mean.alcohol <- mean(df.wines$alcohol)
df.wines$alcohol.z <- (mean.alcohol - df.wines$alcohol) / sd.alcohol
```

