1. Create the vector serial with name using a) c() function, b) a:b function, c) seq() function
serial <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
serial
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12
serial <- c(1:12)
serial
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12
serial <- seq(from = 1, to = 12)
serial
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12
  1. Now use c() function to create the following vectors
before <- c(45, 49, 40, 48, 44, 70, 90, 75, 80, 65, 80, 52)
before
##  [1] 45 49 40 48 44 70 90 75 80 65 80 52
after <- c(43, 50, 61, 44, 45, 20, 85, 65, 72, 65, 70, 75)
after
##  [1] 43 50 61 44 45 20 85 65 72 65 70 75
age <- c(20, 19, 22, 20, 27, 22, 22, 20, 25, 22, 24, 22)
age
##  [1] 20 19 22 20 27 22 22 20 25 22 24 22
 sex <- c("male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female")
sex
##  [1] "male"   "female" "male"   "female" "male"   "female" "male"  
##  [8] "female" "male"   "female" "male"   "female"
eye_color <- c("blue", "blue", "brown", "brown", "blue", "blue", "brown", "brown", "blue", "blue", "brown", "brown")
eye_color
##  [1] "blue"  "blue"  "brown" "brown" "blue"  "blue"  "brown" "brown"
##  [9] "blue"  "blue"  "brown" "brown"
  1. Can you create the vectors sex and eye_color using a function different from the function c()? Answer: No

  2. How many patients are above 20 years old?

sum(age>20)
## [1] 8
  1. What is the median age of the patients?
median(age)
## [1] 22
  1. How many patients have blue eyes?
sum(sex== "male" & eye_color== "blue")
## [1] 3
  1. For example, in another experiment, the psychologist is looking for male patients with brown eyes and female patients with blue eyes from the same data set. What is the sample size of his/her next experiment?
sum(sex=="male" & eye_color=="brown" | sex=="female" & eye_color=="blue")
## [1] 6
  1. How many patients’ results show better score (improvement) after the experiment?
sum(before<after)
## [1] 4
  1. Represent two curves with the results before and after in the same graph. Use a) Different symbol with “pch” and use “cex” to increase the dimension of the symbol
plot(serial, before, type = "o", pch = "+", xlab = "serial", ylab = "result", cex = 2.00, ylim = c(20,90))
points(serial, after, type = "o", pch = "*", cex = 2.00)

  1. Different line types with “lty”, “lwd”
plot(serial, before, type = "o", pch = "+", xlab = "serial;", ylab = "result", cex = 2.00, lty = 1, lwd = 2, ylim = c(20, 90))
points(serial, after, pch = "*", type = "o", cex = 2.00, lty = 3, lwd = 2)

  1. Use different colors to distinguish the two graphs
plot(serial, before, type = "o", pch = "+", xlab = "serial;", ylab = "result", cex = 2.00, lty = 1, lwd = 2, col = "navy", ylim = c(20, 90))
points(serial, after, pch = "*", type = "o", cex = 2.00, lty = 3, lwd = 2, col = "orange")

```

  1. Create a figure with 3 graphs in a row: one with the array “before”, next with “after”, and third one with a difference between before and after. Note that the third graph is related to thr problem #8.
par(mfrow = c(1,3))
plot(before, serial)
plot(after, serial)
plot(before-after, serial)