Question 1

n_dims<-runif(1, min=3, max=10)
print(n_dims)
## [1] 4.099243
# a single random number and output
n_dims2<-(1:n_dims^2)
print(n_dims2)
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
# creates a vector starting at one and ending with the square of the OG random number
rn_dims2<- sample(n_dims2)
#randomizes the vector
keanu<- matrix(data=rn_dims2,nrow=n_dims, n_dims)
print(keanu)
##      [,1] [,2] [,3] [,4]
## [1,]    1    9    2    8
## [2,]   13   10   15    3
## [3,]   11   12    5    4
## [4,]   14   16    7    6
#makes a square matrix
t(keanu)
##      [,1] [,2] [,3] [,4]
## [1,]    1   13   11   14
## [2,]    9   10   12   16
## [3,]    2   15    5    7
## [4,]    8    3    4    6
print(keanu)
##      [,1] [,2] [,3] [,4]
## [1,]    1    9    2    8
## [2,]   13   10   15    3
## [3,]   11   12    5    4
## [4,]   14   16    7    6
sum(keanu[1,1:n_dims])
## [1] 20
mean(keanu[1,1:n_dims])
## [1] 5
sum(keanu[n_dims,1:n_dims]) 
## [1] 43
mean(keanu[n_dims,1:n_dims])
## [1] 10.75
eigen(keanu)
## eigen() decomposition
## $values
## [1] 33.32173278 -6.30068969 -5.09489742  0.07385433
## 
## $vectors
##            [,1]        [,2]        [,3]       [,4]
## [1,] -0.3343208  0.71401549  0.01134466  0.4727103
## [2,] -0.5557624 -0.02651759 -0.63482895 -0.5852498
## [3,] -0.4518375 -0.49015026  0.51358448 -0.1506668
## [4,] -0.6125362 -0.49923084  0.57714338  0.6413479
#Imaginary sums
typeof(eigen(keanu))
## [1] "list"
#list
my_vec<-runif( 16, min=0, max=1)
my_matrix<- matrix(data=my_vec, nrow=4)
print(my_matrix)
##             [,1]      [,2]      [,3]      [,4]
## [1,] 0.007481694 0.6544371 0.5990204 0.4668683
## [2,] 0.052733453 0.2549018 0.9074707 0.5577873
## [3,] 0.138689085 0.4967008 0.8263926 0.5868425
## [4,] 0.480625426 0.3306085 0.7873627 0.6650190
#gives 4X4 matrix of random numbers
#my_lvec<-runif(100, min=5, max=50)
my_logicalv<- runif(100 ,min=1, max=100)
print(my_logicalv)
##   [1] 94.196003 90.119583 25.945705 37.855643 40.026814 63.454202 91.593032
##   [8] 17.221061 42.073781 99.833153 45.928641 77.264790 16.046481 40.039226
##  [15] 44.738453 99.520152 39.616241 67.123240 34.143251 31.635841 47.667416
##  [22]  3.093493  3.600219  2.797631 93.855022 95.438138 16.106158 74.277963
##  [29] 51.265469 71.641502 46.728914 46.341949 29.464103  9.113701 25.109520
##  [36] 70.434328  6.782166 66.236946 57.753244 28.840040 91.904893 17.512781
##  [43]  1.138191 48.574682 78.186432  8.589280 87.865891 75.948610 44.556590
##  [50] 59.231474 31.712712 24.036003 53.803074 25.015629  3.544023 33.651762
##  [57] 36.428892 69.640859 62.559463 79.428073 18.704541 46.500187 54.609513
##  [64]  6.719407 47.142737 61.311242  3.633408 39.816516 98.924744 62.353137
##  [71] 73.233606 72.600501  1.148852 11.749689 26.691396 39.803785 67.445774
##  [78] 93.296432 73.648222 82.152486 43.497217 23.365688 77.762709 41.272444
##  [85] 35.850093 43.791603 18.363668 86.870413 41.153665 35.245386 38.507124
##  [92] 29.477324 30.145801 87.122121 12.670142 32.674284 21.347174 22.211444
##  [99]  8.013831 98.669933
my_logicalv<33 
##   [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
##  [13]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE
##  [25] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
##  [37]  TRUE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE  TRUE FALSE FALSE
##  [49] FALSE FALSE  TRUE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
##  [61]  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
##  [73]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
##  [85] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE  TRUE  TRUE
##  [97]  TRUE  TRUE  TRUE FALSE
my_logical<-
my_letters<- letters
print(my_letters)
##  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
## [20] "t" "u" "v" "w" "x" "y" "z"
my_list1<-list(my_matrix,my_letters)
print(my_list1)
## [[1]]
##             [,1]      [,2]      [,3]      [,4]
## [1,] 0.007481694 0.6544371 0.5990204 0.4668683
## [2,] 0.052733453 0.2549018 0.9074707 0.5577873
## [3,] 0.138689085 0.4967008 0.8263926 0.5868425
## [4,] 0.480625426 0.3306085 0.7873627 0.6650190
## 
## [[2]]
##  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
## [20] "t" "u" "v" "w" "x" "y" "z"
str(my_list1)
## List of 2
##  $ : num [1:4, 1:4] 0.00748 0.05273 0.13869 0.48063 0.65444 ...
##  $ : chr [1:26] "a" "b" "c" "d" ...
my_list2<-list(my_matrix[[2,2]],my_letters[[2]])
print(my_list2)
## [[1]]
## [1] 0.2549018
## 
## [[2]]
## [1] "b"
typeof(my_list2)
## [1] "list"
unrolled<-unlist(my_list2)
print(unrolled)
## [1] "0.254901778651401" "b"
typeof(unrolled)
## [1] "character"
my_unis<- runif(26, min=0,max=10)
my_letters<- sample(LETTERS)
my_dataframe<- data.frame(my_unis,my_letters, stringsAsFactors = FALSE)

print(my_dataframe)
##      my_unis my_letters
## 1  1.3059366          B
## 2  1.4200065          V
## 3  9.5408646          I
## 4  9.9959471          Q
## 5  8.0930868          F
## 6  2.1958076          M
## 7  9.7923434          T
## 8  9.9153678          J
## 9  7.5524880          H
## 10 6.4290072          Y
## 11 6.3558486          Z
## 12 1.7560293          W
## 13 8.3910134          D
## 14 1.0047837          A
## 15 1.9517388          K
## 16 5.3323983          G
## 17 1.4183146          N
## 18 8.6843581          S
## 19 5.4622369          C
## 20 1.6200741          L
## 21 3.3450937          X
## 22 8.0840376          E
## 23 3.4912759          U
## 24 0.1763309          R
## 25 1.9634794          P
## 26 1.9154606          O
my_dataframe$my_unis[sample(my_unis,4)]<-NA
print(my_dataframe)
##      my_unis my_letters
## 1         NA          B
## 2         NA          V
## 3  9.5408646          I
## 4  9.9959471          Q
## 5  8.0930868          F
## 6  2.1958076          M
## 7  9.7923434          T
## 8         NA          J
## 9         NA          H
## 10 6.4290072          Y
## 11 6.3558486          Z
## 12 1.7560293          W
## 13 8.3910134          D
## 14 1.0047837          A
## 15 1.9517388          K
## 16 5.3323983          G
## 17 1.4183146          N
## 18 8.6843581          S
## 19 5.4622369          C
## 20 1.6200741          L
## 21 3.3450937          X
## 22 8.0840376          E
## 23 3.4912759          U
## 24 0.1763309          R
## 25 1.9634794          P
## 26 1.9154606          O
complete.cases(my_dataframe)
##  [1] FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE
## [13]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [25]  TRUE  TRUE
which(!complete.cases(my_dataframe))
## [1] 1 2 8 9
#shows which are NA
print(my_dataframe)
##      my_unis my_letters
## 1         NA          B
## 2         NA          V
## 3  9.5408646          I
## 4  9.9959471          Q
## 5  8.0930868          F
## 6  2.1958076          M
## 7  9.7923434          T
## 8         NA          J
## 9         NA          H
## 10 6.4290072          Y
## 11 6.3558486          Z
## 12 1.7560293          W
## 13 8.3910134          D
## 14 1.0047837          A
## 15 1.9517388          K
## 16 5.3323983          G
## 17 1.4183146          N
## 18 8.6843581          S
## 19 5.4622369          C
## 20 1.6200741          L
## 21 3.3450937          X
## 22 8.0840376          E
## 23 3.4912759          U
## 24 0.1763309          R
## 25 1.9634794          P
## 26 1.9154606          O
my_dataframe<- my_dataframe[order(my_dataframe$my_letters),]

mean('my_unis')
## Warning in mean.default("my_unis"): argument is not numeric or logical:
## returning NA
## [1] NA