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
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"
Can you create the vectors sex and eye_color using a function different from the function c()? Answer: No
How many patients are above 20 years old?
sum(age>20)
## [1] 8
median(age)
## [1] 22
sum(sex== "male" & eye_color== "blue")
## [1] 3
sum(sex=="male" & eye_color=="brown" | sex=="female" & eye_color=="blue")
## [1] 6
sum(before<after)
## [1] 4
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)
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)
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")
```
par(mfrow = c(1,3))
plot(before, serial)
plot(after, serial)
plot(before-after, serial)