Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

R

Views: 4031
Kernel: R (R-Project)

© Copyright 2016 Dr Marta Milo, University of Sheffield.

Week 1 Practical - Solutions

This Notebook contains the solution of the practical assignments for Week 1.

The solution to the exercises assigned but they are not unique. All the exercises proposed can be solved in different manners, some more eficient than other but still correct is the requested output is obtained.

For this reason, when you compare your solutions with these bear in mind that you might have found the solution using a different algorithm and different commands, nonethless they are still correct. These solutions are a guidance and also a surce of ideas that can be merged with yours to build your scripts and to improve it.

To help you to evaluate your notebooks please follow the following criteria:

  • Overall clarity (score = 0.25)

  • Correctness of the code (score = 0.25)

  • Exhaustive cover of required analysis (score= 0.25)

  • Interpretation of the results (score= 0.25)

These criteria are also used when peer-marking and self-marking. Please read the guidelines given to quantify the above criteria with a grade. For Week 1 please score the notebook starting from Excercise 1.

Basic operation in R

Exercise 0: Create a notebook called your_username_week1.ipynb in the Week 1 folder. This is OBviuosly done successfully if you are reading your notebook. 😃

Exercise 1: In your notebook called your_username_week1.ipynb, open a code cell execute the command library() results in. What happens if you type library without parentheses? Write a description of what you've discovered in a Markdown cell

Solution:

library()
MIME type unknown not supported
library
function (package, help, pos = 2, lib.loc = NULL, character.only = FALSE, logical.return = FALSE, warn.conflicts = TRUE, quietly = FALSE, verbose = getOption("verbose")) { testRversion <- function(pkgInfo, pkgname, pkgpath) { if (is.null(built <- pkgInfo$Built)) stop(gettextf("package %s has not been installed properly\n", sQuote(pkgname)), call. = FALSE, domain = NA) R_version_built_under <- as.numeric_version(built$R) if (R_version_built_under < "3.0.0") stop(gettextf("package %s was built before R 3.0.0: please re-install it", sQuote(pkgname)), call. = FALSE, domain = NA) current <- getRversion() if (length(Rdeps <- pkgInfo$Rdepends2)) { for (dep in Rdeps) if (length(dep) > 1L) { target <- dep$version res <- if (is.character(target)) { do.call(dep$op, list(as.numeric(R.version[["svn rev"]]), as.numeric(sub("^r", "", dep$version)))) } else { do.call(dep$op, list(current, as.numeric_version(target))) } if (!res) stop(gettextf("This is R %s, package %s needs %s %s", current, sQuote(pkgname), dep$op, target), call. = FALSE, domain = NA) } } if (R_version_built_under > current) warning(gettextf("package %s was built under R version %s", sQuote(pkgname), as.character(built$R)), call. = FALSE, domain = NA) platform <- built$Platform r_arch <- .Platform$r_arch if (.Platform$OS.type == "unix") { if (!nzchar(r_arch) && length(grep("\\w", platform)) && !testPlatformEquivalence(platform, R.version$platform)) stop(gettextf("package %s was built for %s", sQuote(pkgname), platform), call. = FALSE, domain = NA) } else { if (nzchar(platform) && !grepl("mingw", platform)) stop(gettextf("package %s was built for %s", sQuote(pkgname), platform), call. = FALSE, domain = NA) } if (nzchar(r_arch) && file.exists(file.path(pkgpath, "libs")) && !file.exists(file.path(pkgpath, "libs", r_arch))) stop(gettextf("package %s is not installed for 'arch = %s'", sQuote(pkgname), r_arch), call. = FALSE, domain = NA) } checkLicense <- function(pkg, pkgInfo, pkgPath) { L <- tools:::analyze_license(pkgInfo$DESCRIPTION["License"]) if (!L$is_empty && !L$is_verified) { site_file <- path.expand(file.path(R.home("etc"), "licensed.site")) if (file.exists(site_file) && pkg %in% readLines(site_file)) return() personal_file <- path.expand("~/.R/licensed") if (file.exists(personal_file)) { agreed <- readLines(personal_file) if (pkg %in% agreed) return() } else agreed <- character() if (!interactive()) stop(gettextf("package %s has a license that you need to accept in an interactive session", sQuote(pkg)), domain = NA) lfiles <- file.path(pkgpath, c("LICENSE", "LICENCE")) lfiles <- lfiles[file.exists(lfiles)] if (length(lfiles)) { message(gettextf("package %s has a license that you need to accept after viewing", sQuote(pkg)), domain = NA) readline("press RETURN to view license") encoding <- pkgInfo$DESCRIPTION["Encoding"] if (is.na(encoding)) encoding <- "" if (encoding == "latin1") encoding <- "cp1252" file.show(lfiles[1L], encoding = encoding) } else { message(gettextf("package %s has a license that you need to accept:\naccording to the DESCRIPTION file it is", sQuote(pkg)), domain = NA) message(pkgInfo$DESCRIPTION["License"], domain = NA) } choice <- menu(c("accept", "decline"), title = paste("License for", sQuote(pkg))) if (choice != 1) stop(gettextf("license for package %s not accepted", sQuote(package)), domain = NA, call. = FALSE) dir.create(dirname(personal_file), showWarnings = FALSE) writeLines(c(agreed, pkg), personal_file) } } checkNoGenerics <- function(env, pkg) { nenv <- env ns <- .getNamespace(as.name(pkg)) if (!is.null(ns)) nenv <- asNamespace(ns) if (exists(".noGenerics", envir = nenv, inherits = FALSE)) TRUE else { length(objects(env, pattern = "^\\.__T", all.names = TRUE)) == 0L } } checkConflicts <- function(package, pkgname, pkgpath, nogenerics, env) { dont.mind <- c("last.dump", "last.warning", ".Last.value", ".Random.seed", ".Last.lib", ".onDetach", ".packageName", ".noGenerics", ".required", ".no_S3_generics", ".Depends", ".requireCachedGenerics") sp <- search() lib.pos <- match(pkgname, sp) ob <- objects(lib.pos, all.names = TRUE) if (!nogenerics) { these <- ob[substr(ob, 1L, 6L) == ".__T__"] gen <- gsub(".__T__(.*):([^:]+)", "\\1", these) from <- gsub(".__T__(.*):([^:]+)", "\\2", these) gen <- gen[from != package] ob <- ob[!(ob %in% gen)] } fst <- TRUE ipos <- seq_along(sp)[-c(lib.pos, match(c("Autoloads", "CheckExEnv"), sp, 0L))] for (i in ipos) { obj.same <- match(objects(i, all.names = TRUE), ob, nomatch = 0L) if (any(obj.same > 0)) { same <- ob[obj.same] same <- same[!(same %in% dont.mind)] Classobjs <- grep("^\\.__", same) if (length(Classobjs)) same <- same[-Classobjs] same.isFn <- function(where) vapply(same, exists, NA, where = where, mode = "function", inherits = FALSE) same <- same[same.isFn(i) == same.isFn(lib.pos)] not.Ident <- function(ch, TRAFO = identity, ...) vapply(ch, function(.) !identical(TRAFO(get(., i)), TRAFO(get(., lib.pos)), ...), NA) if (length(same)) same <- same[not.Ident(same)] if (length(same) && identical(sp[i], "package:base")) same <- same[not.Ident(same, ignore.environment = TRUE)] if (length(same)) { if (fst) { fst <- FALSE packageStartupMessage(gettextf("\nAttaching package: %s\n", sQuote(package)), domain = NA) } msg <- .maskedMsg(same, pkg = sQuote(sp[i]), by = i < lib.pos) packageStartupMessage(msg, domain = NA) } } } } if (verbose && quietly) message("'verbose' and 'quietly' are both true; being verbose then ..") if (!missing(package)) { if (is.null(lib.loc)) lib.loc <- .libPaths() lib.loc <- lib.loc[dir.exists(lib.loc)] if (!character.only) package <- as.character(substitute(package)) if (length(package) != 1L) stop("'package' must be of length 1") if (is.na(package) || (package == "")) stop("invalid package name") pkgname <- paste("package", package, sep = ":") newpackage <- is.na(match(pkgname, search())) if (newpackage) { pkgpath <- find.package(package, lib.loc, quiet = TRUE, verbose = verbose) if (length(pkgpath) == 0L) { txt <- if (length(lib.loc)) gettextf("there is no package called %s", sQuote(package)) else gettext("no library trees found in 'lib.loc'") if (logical.return) { warning(txt, domain = NA) return(FALSE) } else stop(txt, domain = NA) } which.lib.loc <- normalizePath(dirname(pkgpath), "/", TRUE) pfile <- system.file("Meta", "package.rds", package = package, lib.loc = which.lib.loc) if (!nzchar(pfile)) stop(gettextf("%s is not a valid installed package", sQuote(package)), domain = NA) pkgInfo <- readRDS(pfile) testRversion(pkgInfo, package, pkgpath) if (!package %in% c("datasets", "grDevices", "graphics", "methods", "splines", "stats", "stats4", "tcltk", "tools", "utils") && isTRUE(getOption("checkPackageLicense", FALSE))) checkLicense(package, pkgInfo, pkgpath) if (is.character(pos)) { npos <- match(pos, search()) if (is.na(npos)) { warning(gettextf("%s not found on search path, using pos = 2", sQuote(pos)), domain = NA) pos <- 2 } else pos <- npos } .getRequiredPackages2(pkgInfo, quietly = quietly) deps <- unique(names(pkgInfo$Depends)) if (packageHasNamespace(package, which.lib.loc)) { if (isNamespaceLoaded(package)) { newversion <- as.numeric_version(pkgInfo$DESCRIPTION["Version"]) oldversion <- as.numeric_version(getNamespaceVersion(package)) if (newversion != oldversion) { res <- try(unloadNamespace(package)) if (inherits(res, "try-error")) stop(gettextf("Package %s version %s cannot be unloaded", sQuote(package), oldversion, domain = "R-base")) } } tt <- try({ ns <- loadNamespace(package, c(which.lib.loc, lib.loc)) env <- attachNamespace(ns, pos = pos, deps) }) if (inherits(tt, "try-error")) if (logical.return) return(FALSE) else stop(gettextf("package or namespace load failed for %s", sQuote(package)), call. = FALSE, domain = NA) else { on.exit(detach(pos = pos)) nogenerics <- !.isMethodsDispatchOn() || checkNoGenerics(env, package) if (warn.conflicts && !exists(".conflicts.OK", envir = env, inherits = FALSE)) checkConflicts(package, pkgname, pkgpath, nogenerics, ns) on.exit() if (logical.return) return(TRUE) else return(invisible(.packages())) } } else stop(gettextf("package %s does not have a namespace and should be re-installed", sQuote(package)), domain = NA) } if (verbose && !newpackage) warning(gettextf("package %s already present in search()", sQuote(package)), domain = NA) } else if (!missing(help)) { if (!character.only) help <- as.character(substitute(help)) pkgName <- help[1L] pkgPath <- find.package(pkgName, lib.loc, verbose = verbose) docFiles <- c(file.path(pkgPath, "Meta", "package.rds"), file.path(pkgPath, "INDEX")) if (file.exists(vignetteIndexRDS <- file.path(pkgPath, "Meta", "vignette.rds"))) docFiles <- c(docFiles, vignetteIndexRDS) pkgInfo <- vector("list", 3L) readDocFile <- function(f) { if (basename(f) %in% "package.rds") { txt <- readRDS(f)$DESCRIPTION if ("Encoding" %in% names(txt)) { to <- if (Sys.getlocale("LC_CTYPE") == "C") "ASCII//TRANSLIT" else "" tmp <- try(iconv(txt, from = txt["Encoding"], to = to)) if (!inherits(tmp, "try-error")) txt <- tmp else warning("'DESCRIPTION' has an 'Encoding' field and re-encoding is not possible", call. = FALSE) } nm <- paste0(names(txt), ":") formatDL(nm, txt, indent = max(nchar(nm, "w")) + 3) } else if (basename(f) %in% "vignette.rds") { txt <- readRDS(f) if (is.data.frame(txt) && nrow(txt)) cbind(basename(gsub("\\.[[:alpha:]]+$", "", txt$File)), paste(txt$Title, paste0(rep.int("(source", NROW(txt)), ifelse(nzchar(txt$PDF), ", pdf", ""), ")"))) else NULL } else readLines(f) } for (i in which(file.exists(docFiles))) pkgInfo[[i]] <- readDocFile(docFiles[i]) y <- list(name = pkgName, path = pkgPath, info = pkgInfo) class(y) <- "packageInfo" return(y) } else { if (is.null(lib.loc)) lib.loc <- .libPaths() db <- matrix(character(), nrow = 0L, ncol = 3L) nopkgs <- character() for (lib in lib.loc) { a <- .packages(all.available = TRUE, lib.loc = lib) for (i in sort(a)) { file <- system.file("Meta", "package.rds", package = i, lib.loc = lib) title <- if (nzchar(file)) { txt <- readRDS(file) if (is.list(txt)) txt <- txt$DESCRIPTION if ("Encoding" %in% names(txt)) { to <- if (Sys.getlocale("LC_CTYPE") == "C") "ASCII//TRANSLIT" else "" tmp <- try(iconv(txt, txt["Encoding"], to, "?")) if (!inherits(tmp, "try-error")) txt <- tmp else warning("'DESCRIPTION' has an 'Encoding' field and re-encoding is not possible", call. = FALSE) } txt["Title"] } else NA if (is.na(title)) title <- " ** No title available ** " db <- rbind(db, cbind(i, lib, title)) } if (length(a) == 0L) nopkgs <- c(nopkgs, lib) } dimnames(db) <- list(NULL, c("Package", "LibPath", "Title")) if (length(nopkgs) && !missing(lib.loc)) { pkglist <- paste(sQuote(nopkgs), collapse = ", ") msg <- sprintf(ngettext(length(nopkgs), "library %s contains no packages", "libraries %s contain no packages"), pkglist) warning(msg, domain = NA) } y <- list(header = NULL, results = db, footer = NULL) class(y) <- "libraryIQR" return(y) } if (logical.return) TRUE else invisible(.packages()) } <bytecode: 0x1d8e868> <environment: namespace:base>

Typing the command library() you do not get any output. The function library() attivates the package ( a collection of functions) that you specify in brackets. If you do not specify anything it will return a void value and no effect on the working environment.

Typing the command library echos the code that implements the function library().

Changing path and verifying location of workspace

Exercise 2: Run the setwd command above in your your_username_week1.ipynb notebook. Verify that you are indeed in the Autumn2016 directory and then set your working directory to be Autumn2016/Week1

setwd("~/Autumn2016")
getwd()
[1] "/projects/81b488df-6f86-4914-a3a2-03e1fb248f11/Autumn2016"
setwd("~/Autumn2016/Week1") getwd()
[1] "/projects/81b488df-6f86-4914-a3a2-03e1fb248f11/Autumn2016/Week1"

I have verified that I am in the directory I wanted to get with the command getwd() before doing any other operation.

Variables

In the above code cell x is variable, x is its name and 1 its value. The symbol <- assigns a value to an object. Basic arithmetic operations can also be done with vectors. The 'raise to the power' operation is performed with the symbol ^. For example three raised to the power 2 is given by 3^2

** Exercise 3:** In your notebook called your_username_week1.ipynb:

Assign the values "3", "10" and "15" to three different objects and perform the following operations storing the results into different objects:

  • sum all three variables

  • take the difference of the first two and divide by the third

  • multiply all three together

  • take the square value of the sum

  • calculate the sum of the vector raised to the power of 4

  • take the square root (sqrt) of the difference of thrird and the first

x<-3 y<-10 z<-15 s<-x+y+z s d<-(x-y)/z cat("Ratio: ", d) m<-x*y*z print(paste("Multiplication: ", m)) v<-s^4 print(paste("Power of 4: \n", v)) sq<-sqrt(z-x) print(sq)
[1] 28
Ratio: -0.4666667[1] "Multiplication: 450" [1] "Power of 4: \n 614656" [1] 3.464102

Exercise 4: In your notebook called your_username_week1.ipynb:

Write code to print your name, your email and the module code separated by a comma.

myname <- "Marta" email <- "[email protected]" module<- "BMS353" message(paste(myname,email,module, sep=",")) print(paste(myname,email,module, sep=","))
Marta,[email protected],BMS353
[1] "Marta,[email protected],BMS353"

Vectors and Matrices

Exercise 5:

In your notebook called your_username_week1.ipynb:

Create a sequence of even numbers ranging from 2 to 30. Create a sequence of odd numbers ranging from 1 to 30. Verify the lengths and calculate the sum of the elements of the even sequence and the sum of the elements of the odd sequence. What are the two values? Calculate the sum of a sequence of numbers ranging from 1 to 30. What do you conclude?

seqe<-seq(2,30, by=2) seqe seqo<-seq(1,30, by=2) seqo
[1] 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29

To verify the length I use the function length()

length(seqe) length(seqo)
[1] 15
[1] 15

The two sequences has the same number of elements since the numbers are consecutive and the range ends with an even number.

s_even<-sum(seqe) s_odd<-sum(seqo) print(paste("Sum of even:", s_even)) print(paste("Sum of odd:", s_odd)) s_total<-sum(1:30) print(paste("Sum of sequence:", s_total))
[1] "Sum of even: 240" [1] "Sum of odd: 225" [1] "Sum of sequence: 465"

The sum of the sequence is given by the sum of the odds and the evens, this is because they are consecutive numbers.

** Numbers as characters**

We can transform numbers to characters using the command as.character(). For example

dept<- "BMS" code<- 353 module<- c(dept,as.character(code)) print(module)

This enable us to concatenate vectors with letters and numbers that are coerced into characters.

Exercise 6: In your notebook called your_username_week1.ipynb:

Create a vector with the following strings: "BMS", "APS", "MBB". Create a vector with the following numbers: 353, 227, 253.

  • concatenate the two vectors

  • create a vector of three elements merging the elements of the two vectors. For example the first element will be BMS353

dept<-c("BMS","APS","MBB") code<-c(353,227,253) module<-c(paste(dept[1],as.character(code[1])),paste(dept[2],as.character(code[2])),paste(dept[3],as.character(code[3]))) module
[1] "BMS 353" "APS 227" "MBB 253"
module<-c(0,0,0) for (i in 1:3){ module[i]<-paste(dept[i],as.character(code[i])) } module
[1] "BMS 353" "APS 227" "MBB 253"

It is possible to use a loop structure like for to repeat a set of instruction for a number of times (in this case 3 times). The counter i tells when to exit loop.

We more often use the command matrix(), to create a matrix or rearrange a set of data. matrix() needs the data, nrow, ncol. For example matrix(data, nrow = 4, ncol = 5)

We can index the elements of M in the same way we used for vectors. The only difference: now we need two indices in the square brackets, because M is two-dimensional. The first index corresponds to the rows, the second to the columns.

Exercise 7: Create new matrices with:

  • The 2x2 matrix forming the upper left corner of M

  • The first two rows with the third column missing

  • Second row with all columns

Comment on dimensions of all these new matrices.

The matrix M has the following form:

M<- matrix(1:20,nrow=4,ncol=5) 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
M1<-M[1:2,1:2] print(M1)
[,1] [,2] [1,] 1 5 [2,] 2 6
M2<-M[1:2,-3] print(M2)
[,1] [,2] [,3] [,4] [1,] 1 5 13 17 [2,] 2 6 14 18
M3<-M[2,] print(M3)
[1] 2 6 10 14 18

The matrices created hgave the following dimensions: M1=[2x2]; M2=[2x3] and M3=[1x5]

rownames(M)<-c("A","B","C","D") colnames(M)<-c("1st", "2nd", "3rd","4th","5th") M

We can now access the data in the matrix using names as index.

M["A",] M[,c("2nd","3rd")]

Exercise 8: In your notebook called your_username_week1.ipynb:

Create a [3x3] matrix containing the number of students for the year "2013-14", "2014-15", "2015-16" in the three module which names are the ones you created in Exercise 6. Use invented numbers. Assign names to columns and rows and print the number of student for BMS353 for all years.

AA<-matrix(1:9,nrow=3,ncol=3) AA[1,]<-c(130,240,150) AA[2,]<-c(160,170,300) AA[3,]<-c(150,240,260) colnames(AA)<-c("2013-14", "2014-15", "2015-16") rownames(AA)<-module AA
2013-14 2014-15 2015-16 BMS 353 130 240 150 APS 227 160 170 300 MBB 253 150 240 260

It also possible to use directly the name of the column instead of the index when creating new column, i.e AA["APS227",]<-c(160,170,300)

Exercise 9: In your notebook called your_username_week1.ipynb:

Create two matrices [3x4] of 12 random integers from 1:100.

  • sum the matrices

  • subtract the matrices

  • multiply the matrices (to perform matrix multiplication you need to use %*% operator. You also want to make sure the dimensions are compatible)

  • calculate the square root of the elements of the matrices

Create the matrices using sequences of random generated number and table them into matrices.

sq1<-sample(1:100, 12, replace=TRUE) sq2<-sample(1:100, 12, replace=TRUE) S1<-matrix(sq1, nrow=3,ncol=4) S2<-matrix(sq2,nrow=3,ncol=4) print(S1) print(S2)
[,1] [,2] [,3] [,4] [1,] 76 76 73 6 [2,] 6 45 91 50 [3,] 93 20 71 94 [,1] [,2] [,3] [,4] [1,] 81 52 18 67 [2,] 92 45 20 14 [3,] 10 62 59 79

Sum of the matrices:

SU<-S1+S2 print(SU)
[,1] [,2] [,3] [,4] [1,] 157 128 91 73 [2,] 98 90 111 64 [3,] 103 82 130 173

Subtraction of matrices

SUB<-S1+S2 print(SUB)
[,1] [,2] [,3] [,4] [1,] 157 128 91 73 [2,] 98 90 111 64 [3,] 103 82 130 173

Multiplication of the matrices.

In order to multiply S1 and S2 I need to make sure the dimensions are compatible, therefore I need to transpose ( change the row with the column) of one of the two. S1=[3x4] and S2=[3x4], the number of col of S1 needs to be the same as the number of row of S2.

S2t<-t(S2) dim(S2t)
[1] 4 3
MS<-S1%*%S2t print(MS)
[,1] [,2] [,3] [1,] 11824 11956 10253 [2,] 7814 5097 12169 [3,] 16149 12192 13785

Square root of the elements of the matrices

SR1<-sqrt(S1) SR2<-sqrt(S2) print(SR1) print(SR2)
[,1] [,2] [,3] [,4] [1,] 8.717798 8.717798 8.544004 2.449490 [2,] 2.449490 6.708204 9.539392 7.071068 [3,] 9.643651 4.472136 8.426150 9.695360 [,1] [,2] [,3] [,4] [1,] 9.000000 7.211103 4.242641 8.185353 [2,] 9.591663 6.708204 4.472136 3.741657 [3,] 3.162278 7.874008 7.681146 8.888194

Create user-defined functions in R

In R it is possible to create small routines ( or functions) that can be called using a single word. For example we can create a function called myFunction which takes a value, raises it to the power of 3 and subtract 1. It will be something like

myFunction <- function(x) { ux <- x^3-1 return(ux) } test<-myFunction(2) # this implements the function with the value 2

What would be the value of test?

IT WOULD BE 7

Exercise 10: In your notebook called your_username_week1.ipynb:

Calculate the sample variance of x=(5,4,3,2,1)x=(5,4,3,2,1) using the formula below. The formula of the sample variance is:

1N1n=1N(xn1Nn=1Nxn)2 \frac{1}{N-1}\sum_{n=1}^{N}{(x_n-\frac{1}{N}\sum_{n=1}^{N}x_n)^2}.

what happens if you use the command var(x)?

Tip: Remember to use the command sum().

N<-5 x<-c(5,4,3,2,1) SV<-(1/(N-1))*sum((x-(sum(x)/N))^2) SV var(x)
[1] 2.5
[1] 2.5

The function var() implements the sample variance for a set of numbers.

Exercise 11 In your notebook called your_username_week1.ipynb:

Create a user-defined function that accepts more than one input argument. This function can do anything you like. Be creative!

I will implemet the normal function in R using a user-defined function. The normal function has the folowing formula:

1σ2πexp(xμ)22σ2\frac{1}{\sigma\sqrt{2\pi}}\exp-{\frac{(x-\mu)^2}{2\sigma^2}}
myNorm <- function(x,sigma,mu) { ux <- 1/(sigma*sqrt(2*pi))*exp(-(x-mu)^2/(2*sigma^2)) return(ux) } myNorm(x,1,0)
[1] 1.486720e-06 1.338302e-04 4.431848e-03 5.399097e-02 2.419707e-01

Exercise 12 In your notebook called your_username_week1.ipynb:

Write a brief summary in bullet points of the content of this week practical

  • Changing path and verifying location

  • Manipulate variables

  • Manipulate vector and matrices

  • Use of strings and numbers in vectors

  • Create your user-defined function