Instructions:

  1. Update your name in the header block, example: author: "Alex Fout"
  2. Select File > Save as and save the file by adding your last name at the beginning with an underscore, example: fout_progress_check_2.rmd
  3. Each time you encounter a purple “Progress Check” block in the textbook, create a new sub-subheading and a new code block for any code you write.
  4. Be sure to run your code chunks when you make them, to make sure everything works!
  5. Your completed assignment should contain all progress checks from Chapter 3 through (and including) Section 4.3
  6. When you’ve completed the assignment, knit the document and make sure the resulting HTML or PDF file looks alright.
  7. Upload the PDF or HTML file to Canvas (Don’t upload the Rmd document).

Example:

If you’re in section 3.1, create a section 3.1 subheading with two #’s:

Section 3.1

Each time you encounter a progress check block in this section, make a sub-subheading with three #’s, and use the number in the lower right corner of the block

1

For each progress check, you’ll create a code chunk for any code you write:

print("here's some code for the first progress check box in 3.1")
## [1] "here's some code for the first progress check box in 3.1"

2

print("here's some code for the second progress check box in 3.1")
## [1] "here's some code for the second progress check box in 3.1"

Section 3.2

Here’s where section 3.2 progress checks will go, etc.

Progress Checks:

Section 3.4

8/(2*(2+2))
## [1] 1

Section 4.1

print("hello, world!")
## [1] "hello, world!"
print("The air is fine!")
## [1] "The air is fine!"
print(1+1)
## [1] 2
print(4>5)
## [1] FALSE
x <- 1+1; print(x); print(x^2)
## [1] 2
## [1] 4
print("This line doesn't have a semicolon")
## [1] "This line doesn't have a semicolon"
print("This line does have a semicolon");
## [1] "This line does have a semicolon"
{
  print("here's some code that's all grouped together")
  print(2^3 - 7)
  w <- "hello"
  print(w)
}
## [1] "here's some code that's all grouped together"
## [1] 1
## [1] "hello"

Section 4.1.5

?print
## starting httpd help server ... done
??print

Section 4.2.4

x <- "5"
y <- 5
z <- (x == y)

1

class(x)
## [1] "character"

2

class(y)
## [1] "numeric"

3

class(z)
## [1] "logical"

Section 4.3.1

m <- c(TRUE, "Hello", 5)
class(m)
## [1] "character"
print(m)
## [1] "TRUE"  "Hello" "5"

R markdown changed all of the data types to charterers, because a vector is an ordered set of data that are all the same type.

empty_int <- integer(45)
empty_cha <- character(2)
empty_log <- logical(1000)

Yes these do make sense. Character’s defined element is ““, which makes sense since all characters must be surrounded by”“. For logical vectors, the defined element is FALSE, which makes sense because logical vectors deal with Trues and Falses.

Section 4.3.1.1

I think the result will be true

vec <- c(4,5,6) # create a vector
vec[3]==6 #Remember what == does?
## [1] TRUE

Section 4.3.1.3

No, I do not think you can multiply a character vector with a numeric vector since the data types are different. However, I do think you can multiply a logical vector with a numerical vector since their base data type is numbers (logical binary (1,0))

a <- c(1,2,3)
b <- c("I", "am", "sam")
c <- c(TRUE, TRUE, FALSE)

error= TRUE
as.numeric(c(T,F,F,T))
## [1] 1 0 0 1
as.character(c(T,F,F,T))
## [1] "TRUE"  "FALSE" "FALSE" "TRUE"

My prediction was incorrect and you cannot multiply vectors with different data types.

Section 4.3.1.7

I predict that the first once will be produced in binary code (0,1) since that is what T/F is in code. I also predict that the other code text will produce “TRUE” and “FALSE” since thats what T/F stand for.

Section 4.3.2

data <- c(1,2,3,4,5,6,7,8,9)
A <- matrix(data, 3,3)
A
##      [,1] [,2] [,3]
## [1,]    1    4    7
## [2,]    2    5    8
## [3,]    3    6    9
(A[1,2])*(A[3,3])
## [1] 36
t(A)
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
## [3,]    7    8    9
A %*% t(A)
##      [,1] [,2] [,3]
## [1,]   66   78   90
## [2,]   78   93  108
## [3,]   90  108  126
data <- c(4.5, 6.1, 3.3, 2.0); A <- matrix(data, 2,3)
## Warning in matrix(data, 2, 3): data length [4] is not a sub-multiple or multiple
## of the number of columns [3]

This code will not run because the data is too small for the given matrix value. There are only 4 data points, and therefore can only have a row/column maximum of 2. By changing the matrix to 2x2, then the code will run

data <- c(4.5, 6.1, 3.3, 2.0); A <- matrix(data, 2,2)
A
##      [,1] [,2]
## [1,]  4.5  3.3
## [2,]  6.1  2.0

Section 4.3.3

S1= character S2= integer S3= character ## Section 4.3.3.2

data <- c(4, 6, 3, 2, 1, 8); A <- matrix(data, 3,3)
vec_1 <- c("hi", "my", "vector")
vec_2 <- c(T,T,F)
special_list <- list(my_matrix=A, my_vector=vec_1, my_logical=vec_2)

Section 4.3.4

# 1. Loading 
data("mtcars")
# 2. Print
head(mtcars)
##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

Column names: mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb

row.names(mtcars)
##  [1] "Mazda RX4"           "Mazda RX4 Wag"       "Datsun 710"         
##  [4] "Hornet 4 Drive"      "Hornet Sportabout"   "Valiant"            
##  [7] "Duster 360"          "Merc 240D"           "Merc 230"           
## [10] "Merc 280"            "Merc 280C"           "Merc 450SE"         
## [13] "Merc 450SL"          "Merc 450SLC"         "Cadillac Fleetwood" 
## [16] "Lincoln Continental" "Chrysler Imperial"   "Fiat 128"           
## [19] "Honda Civic"         "Toyota Corolla"      "Toyota Corona"      
## [22] "Dodge Challenger"    "AMC Javelin"         "Camaro Z28"         
## [25] "Pontiac Firebird"    "Fiat X1-9"           "Porsche 914-2"      
## [28] "Lotus Europa"        "Ford Pantera L"      "Ferrari Dino"       
## [31] "Maserati Bora"       "Volvo 142E"

Data type: integer Row number: 31 Column number: 6

data("USArrests")
     
head(USArrests)
##            Murder Assault UrbanPop Rape
## Alabama      13.2     236       58 21.2
## Alaska       10.0     263       48 44.5
## Arizona       8.1     294       80 31.0
## Arkansas      8.8     190       50 19.5
## California    9.0     276       91 40.6
## Colorado      7.9     204       78 38.7
row.names(USArrests)
##  [1] "Alabama"        "Alaska"         "Arizona"        "Arkansas"      
##  [5] "California"     "Colorado"       "Connecticut"    "Delaware"      
##  [9] "Florida"        "Georgia"        "Hawaii"         "Idaho"         
## [13] "Illinois"       "Indiana"        "Iowa"           "Kansas"        
## [17] "Kentucky"       "Louisiana"      "Maine"          "Maryland"      
## [21] "Massachusetts"  "Michigan"       "Minnesota"      "Mississippi"   
## [25] "Missouri"       "Montana"        "Nebraska"       "Nevada"        
## [29] "New Hampshire"  "New Jersey"     "New Mexico"     "New York"      
## [33] "North Carolina" "North Dakota"   "Ohio"           "Oklahoma"      
## [37] "Oregon"         "Pennsylvania"   "Rhode Island"   "South Carolina"
## [41] "South Dakota"   "Tennessee"      "Texas"          "Utah"          
## [45] "Vermont"        "Virginia"       "Washington"     "West Virginia" 
## [49] "Wisconsin"      "Wyoming"

Column names: Murder, Assault, Rape, Urban Pop Data Type: integer Row number: 50 Column number: 4