Homework 1

Homework 1 - basics of R.

Molly Hackbarth
09-15-2021

Learned from R

As a new student on R, I’ve learned some interesting new ideas!

Basic Math

Below you will find how to do basic math addition, subtraction, multiplication, and division.

5+4
[1] 9
3-2
[1] 1
4/1
[1] 4
3*4
[1] 12
5+4+3*14-2/2
[1] 50

Logical Data

You can also use logic for data! This uses the ==, for equals, > greater than, < less than, and >= equal or greater or <= less than or equal to signs!

4==5
[1] FALSE
2==2
[1] TRUE
3>5
[1] FALSE
10>5
[1] TRUE
15>=15
[1] TRUE
1<=2
[1] TRUE

Assigning Data

You can also assign values to variables.

#create a variable x 

x <- 3

x+5
[1] 8
x*x
[1] 9

Reading Data into R

You can also read and plot data into R!

library(datasets)
plot(iris)

Summarazing Data

You can also use head() to see the first few lines of a table.

library(datasets)
head(iris)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa

Vectoring Data

To vector data you must use c() and <-. Here is a quick set up of if you wanted to find the median of yards ran if it was multiplied by 100.

yards <- c(12,50,100,22)

run_yards <- yards*100

Distill is a publication format for scientific and technical writing, native to the web.

Learn more about using Distill at https://rstudio.github.io/distill.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY-NC 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

Hackbarth (2021, Sept. 15). DACSS 601 Fall 2021: Homework 1. Retrieved from https://mrolfe.github.io/DACSS601Fall21/posts/2021-09-15-homework-1-molly-hackbarth/

BibTeX citation

@misc{hackbarth2021homework,
  author = {Hackbarth, Molly},
  title = {DACSS 601 Fall 2021: Homework 1},
  url = {https://mrolfe.github.io/DACSS601Fall21/posts/2021-09-15-homework-1-molly-hackbarth/},
  year = {2021}
}