1. Create the vector serial with name serial using
  1. c() function
serial <- c(1,2,3,4,5,6,7,8,9,10,11,12)
  1. using a:b function
serial <- 1:12
  1. using seq() function.
serial <- seq(from=1,to=12)



2. Now use c() function to create the following vectors: a) before

before <- c(45,49,40,48,44,70,90,75,80,65,80,52)
  1. after
after <- c(43,50,61,44,45,20,85,65,72,65,70,75)
  1. age
age <- c(20,19,22,20,27,22,22,20,25,22,24,22)
  1. sex
sex <- c("male","female","male","female","male","female","male","female","male","female","male","female")
  1. eye_color
eye_color <- c("blue","blue","brown","brown","blue","blue","brown","brown","blue","blue","brown","brown")



3. Can you create the vectors sex and eye_color using a function different from the function c()?

sex2 <- list("male","female","male","female","male","female","male","female","male","female","male","female")
eye_color2 <- list("blue","blue","brown","brown","blue","blue","brown","brown","blue","blue","brown","brown")



4. How many of the patients are above 20 years old?

length(age[age>20])
## [1] 8



5. What is the median age of the patients?

median(age)
## [1] 22



6. How many male patients have blue eye?

length(sex[sex=="male" & eye_color=="blue"])
## [1] 3



7.For example, in another experiment, the psychologist is looking for male patients with brown eye and female patient with blue eye from the same data set. What is the sample size of his/her next experiment?

length(sex[sex=="male" & eye_color=="brown"]) + length(sex[sex=="female" & eye_color=="blue"])
## [1] 6



8.How many patients’ results shows better score (improvement) after the experiment?

length(after[after>before])
## [1] 4



9.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. b) Different line types with “lty”, “lwd” c) Use different colors to distinguish two graphs.

plot(before, type="l",lty=9,lwd=3,col="blue")
points(before, pch=0, cex=2, col="red")
lines(after,lty=9,lwd=3,col="orange")
points(after, pch=1, cex=2, col="green")



10.. 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 the problem #8.

par(mfrow=c(1,3))
plot(before, type="b",lty=9,lwd=3,pch=0,cex=2, col="blue")
plot(after, type="b",lty=9,lwd=3,pch=1,cex=2, col="red")
plot(after-before, type="b",lty=9,lwd=3,pch=2,cex=2, col="green")