October 8, 2018
At the end of the exam you sent me a file
How can we verify that we have the same file?
How can we be sure that nobody changed it?
How to be sure without showing the content of the file?
An answer to these question is given by digital signatures
They are not digital pictures of a handwritten signature
Instead they are a unique number that identifies the exact document
This number is called digest. It is produced by a crypotgraphic hash function
Go to http://onlinemd5.com/ or any other service you find on Google
The evaluation is done in your computer. The file is not sent by the internet
You can take the file you attached, get the digest and compare with the one I created
If they are the same we are sure that I have your file
And we do not need to show the content
Imagine you are working in a project
You can get the MD5 digest and publish it
Objects in R:
Like vectores, but mixing different kinds of elements
people <- list(c(60, 72, 57, 90, 95, 72), c(1.75, 1.80, 1.65, 1.90, 1.74, 1.91), c("Ali", "Deniz", "Fatma", "Emre", "Volkan", "Onur"), TRUE, c(2017, 10, 10), factor(c("M","F","F","M","M","M")))
Notice that elements can have different length
people
[[1]] [1] 60 72 57 90 95 72 [[2]] [1] 1.75 1.80 1.65 1.90 1.74 1.91 [[3]] [1] "Ali" "Deniz" "Fatma" "Emre" "Volkan" "Onur" [[4]] [1] TRUE [[5]] [1] 2017 10 10 [[6]] [1] M F F M M M Levels: F M
people[1:2]
[[1]] [1] 60 72 57 90 95 72 [[2]] [1] 1.75 1.80 1.65 1.90 1.74 1.91
This is a sublist (with one element):
people[1]
[[1]] [1] 60 72 57 90 95 72
This is an element:
people[[1]]
[1] 60 72 57 90 95 72
people <- list(weight=c(60, 72, 57, 90, 95, 72), height=c(1.75, 1.80, 1.65, 1.90, 1.74, 1.91), names=c("Ali", "Deniz", "Fatma", "Emre", "Volkan", "Onur"), valid=TRUE, YMD=c(2017, 10, 10), gender=factor(c("M","F","F","M","M","M")))
How else can we assign names?
people
$weight [1] 60 72 57 90 95 72 $height [1] 1.75 1.80 1.65 1.90 1.74 1.91 $names [1] "Ali" "Deniz" "Fatma" "Emre" "Volkan" "Onur" $valid [1] TRUE $YMD [1] 2017 10 10 $gender [1] M F F M M M Levels: F M
people[1:2]
$weight [1] 60 72 57 90 95 72 $height [1] 1.75 1.80 1.65 1.90 1.74 1.91
This is a sublist:
people[1]
$weight [1] 60 72 57 90 95 72
This is an element:
people[[1]]
[1] 60 72 57 90 95 72
people[[1]]
[1] 60 72 57 90 95 72
people[["weight"]]
[1] 60 72 57 90 95 72
people$weight
[1] 60 72 57 90 95 72
Indices can also be used to change specifc parts of a list.
For example we can update the names
people$names <- toupper(people$names) people$names
[1] "ALI" "DENIZ" "FATMA" "EMRE" "VOLKAN" "ONUR"
people$valid <- NULL people$YMD <- NULL people
$weight [1] 60 72 57 90 95 72 $height [1] 1.75 1.80 1.65 1.90 1.74 1.91 $names [1] "ALI" "DENIZ" "FATMA" "EMRE" "VOLKAN" "ONUR" $gender [1] M F F M M M Levels: F M
people$BMI <- people$weight/people$height^2 people
$weight [1] 60 72 57 90 95 72 $height [1] 1.75 1.80 1.65 1.90 1.74 1.91 $names [1] "ALI" "DENIZ" "FATMA" "EMRE" "VOLKAN" "ONUR" $gender [1] M F F M M M Levels: F M $BMI [1] 19.59184 22.22222 20.93664 24.93075 31.37799 19.73630
[[]]
[]
Try these
people[[2]] people[2] people[[2]][3] people[2][3] people[[1:3]] people[1:3] people[["weight"]] people$weight people["weight"]
people[[2]]
[1] 1.75 1.80 1.65 1.90 1.74 1.91
people[2]
$height [1] 1.75 1.80 1.65 1.90 1.74 1.91
people[[2]][3]
[1] 1.65
people[2][3]
$<NA> NULL
people[[1:3]]
Error in people[[1:3]]: recursive indexing failed at level 2
people[1:3]
$weight [1] 60 72 57 90 95 72 $height [1] 1.75 1.80 1.65 1.90 1.74 1.91 $names [1] "ALI" "DENIZ" "FATMA" "EMRE" "VOLKAN" "ONUR"
people[["weight"]]
[1] 60 72 57 90 95 72
people$weight
[1] 60 72 57 90 95 72
people["weight"]
$weight [1] 60 72 57 90 95 72
If key <- "names"
,
What is the diference between the following?
people[[key]]
people[[names]]
people$key
people$names
Explain