Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

R

Views: 4040
Kernel: R

Execises 0 and 1 not completed No marks awarded.

getwd()
[1] "/projects/fc96d042-48c2-4479-9884-fc9a89f4e931/Autumn2016/Week1"
setwd('~/Autumn2016')

Exercise 2 Working directory not set to Autumn2016/Week1

  • Overall clarity 0.25

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0

  • Interpretation of the results N/A 0.25

  • Total score 0.75

objects()
[1] "a" "b" "c" "data" "M" [6] "mx" "myfunction" "n" "S" "sum" [11] "test" "x" "X" "y" "z"
x<-3 y<-10 z<-15 w<-(x+y+z) return((y-x)/z) x*y*z sqrt(w) w^4 a<-(z-x) sqrt(a)
[1] 0.4666667
[1] 450
[1] 5.291503
[1] 614656
[1] 3.464102

Ecercise 3 Questions not completed: Sum all three variables

  • Overall clarity 0.15

  • Correctness of the code 0.20

  • Exhaustive cover of the required analysis 0.20

  • Interpretation of the results N/A 0.25

  • Total score 0.80

INSTRUCTOR Ecercise 3 Questions not completed: Sum all three variables

  • Overall clarity 0

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results N/A 0.25

  • Total score 0.75

myname <- "Joe" Greeting <- "Hello my name is" info <- "and I'm studying bioinformatics" message <- paste(Greeting,myname,info,sep=" ") print(message)
[1] "Hello my name is Joe and I'm studying bioinformatics"
[1] 55
[1] 10

Exercise 4 Question not followed strictly, however all correct

  • Overall clarity 0.25

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results N/A 0.25

  • Total score 1

x <- 1:10
assign('hello', 1:10) print(hello) sum(hello) length(hello) hello[5] hello[3:8]
[1] 1 2 3 4 5 6 7 8 9 10
[1] 55
[1] 10
[1] 5
[1] 3 4 5 6 7 8
assign('hello', 1:100) print (hello) sum(hello)
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 [91] 91 92 93 94 95 96 97 98 99 100
[1] 5050
sample(1:100, 12, replace=TRUE) runif(4, min=10, max=900) rnorm(10, mean=100, sd=50)
[1] 85 91 98 78 70 19 22 38 15 100 69 86
[1] 798.0764 899.3345 327.4512 772.4725
[1] 80.88413 53.51888 135.19825 80.07381 164.96422 130.77573 88.65916 [8] 98.65834 102.19439 103.92827
x <- seq(length=15,from=2,by=2) print(x) length(x) sum(x) y <- seq(length=15,from=1,by=2) print(y) sum(y) z <- seq(length=30,from=1,by=1) print(z) sum(z) #The sum value of z is almost double that of x and y.
[1] 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
[1] 15
[1] 240
[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
[1] 225
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [26] 26 27 28 29 30
[1] 465

Exercise 5

  • Overall clarity 0.25

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results 0.25 INSTRUCTOR: Interpretation is incomplete. You can aonly have that since they are consecutive numbers.

  • Total score 1 INSTRUCTOR: Score 0.75

greeting <- "how's it going" number <- 78953728462 message <- c(greeting,as.character(number)) print(message)
[1] "how's it going" "78953728462"
Courses <- c("BMS", "APS", "MBB") Numbers <- c(353,227,253) message <- c(Courses,as.character(Numbers)) print(message) Modules <- Map(c,Courses,Numbers) print(Modules)
[1] "BMS" "APS" "MBB" "353" "227" "253" $BMS [1] "BMS" "353" $APS [1] "APS" "227" $MBB [1] "MBB" "253"

Exercise 6

  • Overall clarity 0.25

  • Correctness of the code0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results 0.25

  • Total score 1

INSTRUCTOR

  • Overall clarity 0.25

  • Correctness of the code0.25

  • Exhaustive cover of the required analysis 0

  • Interpretation of the results 0.25

  • Total score 0.75

The solution given was not what the exercise required.

A<-1:50 dim(A)<-c(10,5) A B<-1:100 dim(B)<-c(2,50) B X<-51:100 dim(X)<-c(2,25) X
[,1] [,2] [,3] [,4] [,5] [1,] 1 11 21 31 41 [2,] 2 12 22 32 42 [3,] 3 13 23 33 43 [4,] 4 14 24 34 44 [5,] 5 15 25 35 45 [6,] 6 16 26 36 46 [7,] 7 17 27 37 47 [8,] 8 18 28 38 48 [9,] 9 19 29 39 49 [10,] 10 20 30 40 50
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,] 1 3 5 7 9 11 13 15 17 19 ⋯ 81 83 85 [2,] 2 4 6 8 10 12 14 16 18 20 ⋯ 82 84 86 [,15] [,16] [,17] [,18] [,19] [,20] [,21] [1,] 87 89 91 93 95 97 99 [2,] 88 90 92 94 96 98 100
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,] 51 53 55 57 59 61 63 65 67 69 ⋯ 81 83 85 [2,] 52 54 56 58 60 62 64 66 68 70 ⋯ 82 84 86 [,15] [,16] [,17] [,18] [,19] [,20] [,21] [1,] 87 89 91 93 95 97 99 [2,] 88 90 92 94 96 98 100
Error in rbind(B, X): number of columns of matrices must match (see arg 2) Traceback: 1. rbind(B, X)
matrix(1:40,nrow=4,ncol=10)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 5 9 13 17 21 25 29 33 37 [2,] 2 6 10 14 18 22 26 30 34 38 [3,] 3 7 11 15 19 23 27 31 35 39 [4,] 4 8 12 16 20 24 28 32 36 40
a <-c(matrix(1:5,nrow=1,ncol=5)) b <-c(matrix(6:10,nrow=1,ncol=5)) rbind(a,b) cbind(a,b)
[,1] [,2] [,3] [,4] [,5] a 1 2 3 4 5 b 6 7 8 9 10
a b [1,] 1 6 [2,] 2 7 [3,] 3 8 [4,] 4 9 [5,] 5 10
M <- matrix(1:20,nrow=4,ncol=5) M m <- matrix(1:4,nrow=2,ncol=2) m[1,2] = 5 m[2,2] = 6 m
[,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20
[,1] [,2] [1,] 3 5 [2,] 4 6
M <- matrix(1:20,nrow=4,ncol=5) M c <- matrix(1:8,nrow=2,ncol=4) c[1,2] = 5 c[2,2] = 6 c[1,3] = 13 c[2,3] = 14 c[1,4] = 17 c[2,4] = 18 c
[,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20
[,1] [,2] [,3] [,4] [1,] 1 5 13 17 [2,] 2 6 14 18
M <- matrix(1:20,nrow=4,ncol=5) M z <- matrix(1:5,nrow=1,ncol=5) z[1,1] = 2 z[1,2] = 6 z[1,3] = 10 z[1,4] = 14 z[1,5] = 18 z
[,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20
[,1] [,2] [,3] [,4] [,5] [1,] 2 6 10 14 18

Exercise 7

  • Overall clarity 0.15

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results 0.25

  • Total Score 0.9

INSTRUCTOR*

  • Overall clarity 0

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results 0.25

  • Total Score 0.75

Excellent exploration of function to manipulate matrices but clarity here was essential and it is missing. When you use a new method you need to explain what you are doing.

x <- matrix(1:9,nrow=3,ncol=3) rownames(x)<-c('2013-2014','2014-2015','2015-2016') colnames(x)<-c('BMS353','APS227','MBB253') x[1,1] = sample(200:350, 1, replace=TRUE) x[1,2] = sample(200:350, 1, replace=TRUE) x[1,3] = sample(200:350, 1, replace=TRUE) x[2,1] = sample(200:350, 1, replace=TRUE) x[2,2] = sample(200:350, 1, replace=TRUE) x[2,3] = sample(200:350, 1, replace=TRUE) x[3,1] = sample(200:350, 1, replace=TRUE) x[3,2] = sample(200:350, 1, replace=TRUE) x[3,3] = sample(200:350, 1, replace=TRUE) x S = x[1,1]+x[2,1]+x[3,1] S
BMS353 APS227 MBB253 2013-2014 220 290 255 2014-2015 282 316 229 2015-2016 289 294 257
[1] 791

Exercise 8

  • Overall clarity 0.25

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results 0.25

  • Total Score 1

  • Overall clarity 0

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results 0.25

  • Total Score 0.75

The code used is correct, but very ineffective. Is there a way to doit more efficiently ( i.e two lines)? Clarity here is essential

a <- matrix(nrow=3,ncol=4) b <- matrix(nrow=3,ncol=4) a[1,1] = runif(1, min=1, max=100) a[1,2] = runif(1, min=1, max=100) a[1,3] = runif(1, min=1, max=100) a[1,4] = runif(1, min=1, max=100) a[2,1] = runif(1, min=1, max=100) a[2,2] = runif(1, min=1, max=100) a[2,3] = runif(1, min=1, max=100) a[2,4] = runif(1, min=1, max=100) a[3,1] = runif(1, min=1, max=100) a[3,2] = runif(1, min=1, max=100) a[3,3] = runif(1, min=1, max=100) a[3,4] = runif(1, min=1, max=100) b[1,1] = runif(1, min=1, max=100) b[1,2] = runif(1, min=1, max=100) b[1,3] = runif(1, min=1, max=100) b[1,4] = runif(1, min=1, max=100) b[2,1] = runif(1, min=1, max=100) b[2,2] = runif(1, min=1, max=100) b[2,3] = runif(1, min=1, max=100) b[2,4] = runif(1, min=1, max=100) b[3,1] = runif(1, min=1, max=100) b[3,2] = runif(1, min=1, max=100) b[3,3] = runif(1, min=1, max=100) b[3,4] = runif(1, min=1, max=100) a b a+b a-b a*b sqrt(a) sqrt(b)
[,1] [,2] [,3] [,4] [1,] 79.83892 57.78864 11.25380 54.84656 [2,] 69.32068 59.69974 10.52954 98.08338 [3,] 46.72781 58.75983 30.67213 35.71172
[,1] [,2] [,3] [,4] [1,] 75.18560 22.42895 21.58148 64.05056 [2,] 39.11147 39.45464 74.43411 56.72634 [3,] 18.86983 44.73048 11.13378 40.71691
[,1] [,2] [,3] [,4] [1,] 155.02452 80.21759 32.83528 118.89712 [2,] 108.43215 99.15438 84.96364 154.80972 [3,] 65.59764 103.49031 41.80591 76.42863
[,1] [,2] [,3] [,4] [1,] 4.653324 35.35968 -10.32768 -9.204006 [2,] 30.209210 20.24509 -63.90457 41.357034 [3,] 27.857983 14.02936 19.53835 -5.005190
[,1] [,2] [,3] [,4] [1,] 6002.7371 1296.139 242.8736 3512.953 [2,] 2711.2336 2355.432 783.7567 5563.911 [3,] 881.7459 2628.356 341.4969 1454.071
[,1] [,2] [,3] [,4] [1,] 8.935263 7.601884 3.354668 7.405846 [2,] 8.325904 7.726560 3.244925 9.903705 [3,] 6.835775 7.665496 5.538242 5.975929
[,1] [,2] [,3] [,4] [1,] 8.670963 4.735922 4.645587 8.003160 [2,] 6.253916 6.281293 8.627520 7.531689 [3,] 4.343942 6.688085 3.336733 6.380981

Exercise 9 Matrix not transposed when multiplying

  • Overall clarity 0.25

  • Correctness of the code 0.15

  • Exhaustive cover of the required analysis 0.15

  • Interpretation of the results 0.25

  • Total score 0.8

INSTRUCTOR:

  • Overall clarity 0

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0

  • Interpretation of the results 0.25

  • Total score 0.5

Same as above regarding the efficiency of coding. Multiplication of matrices is given by %*% which requires correct dimensions.

myfunction <-function(x) { result <- var(x) return (result) } test<-myfunction(runif(12,min=100,max=200)) test
[1] 951.0467
x<-runif(12,min=30,max=40) x var(x)
[1] 38.50974 37.84600 37.14590 30.09489 31.58794 34.57360 38.40351 34.81073 [9] 38.06217 32.92062 37.50918 34.01496
[1] 8.27199
x <-c(5,4,3,2,1) n <- length(x) mx <- mean(x) sum((((mx-5)^2)+((mx-4)^2)+((mx-3)^2)+((mx-2)^2)+((mx-1)^2))/(n-1))
[1] 2.5

Exercise 10 Did not test var(x) command.

  • Overall clarity 0.25

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.15

  • Interpretation of the results 0.25

  • Total Score 0.9

INSTRUCTOR

  • Overall clarity 0

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0

  • Interpretation of the results 0

  • Total Score 0.25

You did not answer the question asked and clarity is essential when using alternatives methods. Is essentail always.

myfunction <- function(x, y, z){ c <- x + y + z return (c) } test<-myfunction(4, 7, 50) test
[1] 61

Exercise 11

  • Overall clarity 0.25

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results 0.25

  • Total Score 1

Things Covered in This Week's Practical

  • Creating vectors.

  • Creating matrices.

  • Carrying out functions on vectors and matrices.

  • Binding matrices and vectors.

  • Calculating variance using the formula provided and the var() function.

  • Using myfunction to create user-defined functions.

** Exercise 12**

  • Overall clarity 0.25

  • Correctness of the code 0.25

  • Exhaustive cover of the required analysis 0.25

  • Interpretation of the results 0.25

  • Total Score 1

** Final comments**Final score = 10.15 Overall correct, however please follow the questions, and indicate the exercise numbers, as it had made marking very difficult.

INSTRUCTOR: You must answer the questions asked, since your overall grade will get compromised if you don't. YOur effort of finding new methods is great but needs clarity which also will compromise your final grade if missing. Score 9.5