# Your pythagorean theorem code goes here
Homework 3: Basic Data Types
Download the starter qmd file here
Pythagorean Theorem in R
\[a^2 + b^2 = c^2\]
Use the chunk below to define variables \(a\), \(b\), and \(c\), where you set \(a\) and \(b\) and \(c\) is determined mathematically. You may need to find the square root function in R to make this work.
Quadratic Formula in Python
\[x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\]
Use the chunk below to define variables \(a\), \(b\), and \(c\), and then define \(x1\) and \(x2\), the possible values for \(x\).
# Your quadratic formula code goes here
Debugging practice
Look at the data frame below, which contains 3 columns: Name
, Salary
, and Hire.Year
. You’ve read in this data from the data file online and ideally, you want to plot Hire.Year
on the x-axis and Salary
on the y-axis (code to do this is provided).
Unfortunately, the data isn’t reading in properly. Identify the problem, propose a solution, and try to implement your solution using functions on the R reference card.
Some things you may want to consider:
gsub
- You can access columns in a data frame using
$
:df$col1
will get youcol1
of thedf
object. (We will talk about data frames more next week, but for now, just try to use them) - You can access items in a vector using
[]
:x[1]
will get you the first item inx
Note: You should be able to identify the problem given what you know about R from this chapter. You may not be able to implement a solution without some additional research, so if you don’t get that far that’s ok.
# This line reads in a tab-separated data file with a header naming the columns
<- read.table("https://raw.githubusercontent.com/srvanderplas/unl-stat151/main/homework/03-data.tsv",
salary sep = "\t", header = T)
# This code plots labels for each individual at location (x, y)
library(ggplot2)
ggplot(salary, aes(x = Hire.Year, y = Salary, label = Name)) +
geom_label()
# This displays the salary object
salary
Name Salary Hire.Year
1 Michael Scott $67,872.00 1995
2 Dwight Schrute 54000 2001
3 Pam Beesly 26309 2003
4 Jim Halpert 59083 1998
The problem with the data is:
Here is how I solved the problem:
# Your implementation code goes here