Problem 1
## Load csv, assign it to the data.frame hearattack
heartattack <- read.csv("http://vincentarelbundock.github.io/Rdatasets/csv/DAAG/mifem.csv")
#providing a mean of yronset, does not provide relevant information, but it's one of the three values
#I can average
summarize(heartattack,mean(age),median(age),mean(yronset),median(yronset))
#much more interesting summary
#mean of age with outcomes by year
summarize(group_by(heartattack,Year=yronset,outcome),mean(age),median(age),count=n())
Problem 2
## Filtering out the 1992 data and creating a new data.frame MINT= Myocardial Infarction Ninety-Two
MINT <- filter(heartattack, yronset == 92)
Problem 3
##renaming the columns, useful especially for PreMI and SmStat
colnames(MINT) <- c("Number","Living","AgeMI","YearMI","PreviousMI","Smoker","DiabetesY/N","HighBloodPressure","HighCholesterol","AnginaHistory","PreviousStroke")
Problem 4
## providing means and medians again
summarize(MINT,mean(AgeMI),median(AgeMI),mean(YearMI),median(YearMI))
Problem 5
##changing the values for the answer to the smoking question
##I ordered the Smoker factor to maker sure that the substitution actually went to the correct values
##This can also be done with as.character(), but I felt this was cleaner
MINT$Smoker<-factor(MINT$Smoker,levels(MINT$Smoker), ordered = TRUE)
levels(MINT$Smoker) <-c("Current","Never","Unknown","Former")
Problem 6
##Showing that it worked, have to go to row 14 to see the first unknown for smoker
head(MINT,14)