Create the vector serial with name serial using
serial = c(1,2,3,4,5,6,7,8,9,10,11,12)
serial = 1:12
serial = seq(from=1, to= 12)
Now use c() functino to create the following vectors
before = c(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)
age = c(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")
eye_color = c("blue", "blue", "brown", "brown", "blue", "blue", "brown", "brown", "blue", "blue", "brown", "brown")
Can you create the vectors sex and eye_color using function different from the function c()?
I don’t believe there is any other way to enter string into a data set, unless there is a data set already created and can be imported. Theres a way to to make it easier if there is a pattern in sex and eye_color that can be used in order to reduce the amount of input needed by the user, using the paste().
sex1=c ("male", "female")
vector = 1:12
eye_color1 = paste(sex1,vector)
This method would have a 1-12 in the data and to get it out would probably take longer than just inputing it originally. There has to be another easier way to input too without copying every single one but I did not know how.
How many of the patients are above 20 years old?
11 out of 12
sum(age >= 20)
## [1] 11
What is the median age of the patients?
22
median(age)
## [1] 22
How many male patients have blue eyes?
3 out of the 6 males
sum(sex == "male" & eye_color == "blue")
## [1] 3
For example, in another experiment, the psychologist is looking for male patients with brown eye and female patient with blue eyes from the same data set. What is the sample size of his/her next experiment?
Sample size of 6 using this data
sum(sex == "male" & eye_color == "brown"| sex == "female" & eye_color == "blue")
## [1] 6
How many patients’ results shows better score (imporvement) after the experiment?
4 patients showed positive results after
sum(after[1:12] > before [1:12])
## [1] 4
Represent two curves with the results before and affter in the same graph. Use
plot(serial, before, pch = "*", cex = 1.75, xlab = "Patient", ylab= "Effect", ylim=c(20,90))
points(serial, after, col = "black", pch = "+")
lines(serial, after, lty=9, lwd= 2.5, col="blue")
lines(serial, before, lty=2, lwd= 2.5, col="yellow")
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(serial, before, main="Patients - Before")
plot(serial,after, main="Patients - After")
plot(serial, before-after, main="Difference Before and After")
OR
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))
plot(serial, before-after, main="Difference Before and After")
plot(serial, before, main="Patients - Before")
plot(serial,after, main="Patients - After")