Assignment

This assignment will explore real estate prices using another data set from Kaggle. You should download the data from here and place it in your data_raw folder.

Problem 1.

Read the dataset into R to an object called housing and print the shape of the data frame

housing <- read.csv("https://github.com/CSU-R/Module1/raw/master/data_raw/housing.csv")

Problem 2

Below is some incomplete code that you must finish. The purpose of the code is to loop through each column in the data frame and determine how many columns have type “character”. Replace both sets of ... below to accomplish the task Don’t change any other code.

is_quant <- 0  # counter
for(i in names(housing)){
  col <- housing[,i]
  if(is.character(col)){
    # increase counter by 1
    is_quant <- is_quant + 1
  }
}

Problem 3

Below is a list of some of the quantitative variables. Write a for loop which iterates through the list and prints the range (maximum minus minimum). Remember, you may have to use na.rm=T if you encounter NA values.

qvs <- list(housing$LotFrontage, housing$LotArea, housing$SalePrice, housing$Fireplaces)

for(i in qvs){
  print(max(i, na.rm = T)-min(i, na.rm = T))
}
## [1] 292
## [1] 213945
## [1] 720100
## [1] 3

Problem 4

Write code that computes the average sale price for houses, split by number of Fireplaces

for(i in unique(housing$Fireplaces)){
  price <- housing[housing$Fireplaces == i,"SalePrice"]
  print(mean(price))
}
## [1] 141331.5
## [1] 211843.9
## [1] 240588.5
## [1] 252000

Problem 5

How many houses have a garage built after 1995?

garage_index <- housing$GarageYrBlt > '1995'
num_garage <- sum(garage_index, na.rm = T)
print(num_garage)
## [1] 502

Problem 6

Find two quantitative variables in the data set, and create a plot between them. Make an observation about the relationship between the two variables. If no relationship is clear, try two other quantitative variables.

plot(x = housing$LotFrontage, y = housing$SalePrice, main = "Sale Price vs Lot Frontage", xlab="Lot Frontage", ylab="Sale Price")

It appears that there is a relationship between Lot Frontage and Sale Price, as lot frontage decreases, sale price also decreases.

Problem 7

What was the most valuable thing you got from this course? The most valuable think I learned from this course is how to use r and more effectively store things on my computer. I have never done any kind of coding before so this was all new to me. Also, I am not the most tech savvy person so creating folders was also helpful.

Problem 8

What was the least valuable part of the course? I prefered the lectures where we worked through problems on the homework than just going off of slides, I feel like that was most helpful for this class.

Problem 9

What is one thing that could be improved about the course? As I mentioned in question 8, going over homeworks and questions in class was very helpful as opposed to lecturing off slides.

Problem 10

Anything else you’d like to share? Nope! Thank you for the great semester!