R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

#1.Use the summary function to gain an overview of the data set. Then display the mean and median.
theUrl<-"https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/boot/poisons.csv"
Animal<-read.table(file=theUrl, header=TRUE, sep=",")
Animal
##     X time poison treat
## 1   1 0.31      1     A
## 2   2 0.45      1     A
## 3   3 0.46      1     A
## 4   4 0.43      1     A
## 5   5 0.36      2     A
## 6   6 0.29      2     A
## 7   7 0.40      2     A
## 8   8 0.23      2     A
## 9   9 0.22      3     A
## 10 10 0.21      3     A
## 11 11 0.18      3     A
## 12 12 0.23      3     A
## 13 13 0.82      1     B
## 14 14 1.10      1     B
## 15 15 0.88      1     B
## 16 16 0.72      1     B
## 17 17 0.92      2     B
## 18 18 0.61      2     B
## 19 19 0.49      2     B
## 20 20 1.24      2     B
## 21 21 0.30      3     B
## 22 22 0.37      3     B
## 23 23 0.38      3     B
## 24 24 0.29      3     B
## 25 25 0.43      1     C
## 26 26 0.45      1     C
## 27 27 0.63      1     C
## 28 28 0.76      1     C
## 29 29 0.44      2     C
## 30 30 0.35      2     C
## 31 31 0.31      2     C
## 32 32 0.40      2     C
## 33 33 0.23      3     C
## 34 34 0.25      3     C
## 35 35 0.24      3     C
## 36 36 0.22      3     C
## 37 37 0.45      1     D
## 38 38 0.71      1     D
## 39 39 0.66      1     D
## 40 40 0.62      1     D
## 41 41 0.56      2     D
## 42 42 1.02      2     D
## 43 43 0.71      2     D
## 44 44 0.38      2     D
## 45 45 0.30      3     D
## 46 46 0.36      3     D
## 47 47 0.31      3     D
## 48 48 0.33      3     D
summary(Animal)
##        X              time            poison  treat 
##  Min.   : 1.00   Min.   :0.1800   Min.   :1   A:12  
##  1st Qu.:12.75   1st Qu.:0.3000   1st Qu.:1   B:12  
##  Median :24.50   Median :0.4000   Median :2   C:12  
##  Mean   :24.50   Mean   :0.4794   Mean   :2   D:12  
##  3rd Qu.:36.25   3rd Qu.:0.6225   3rd Qu.:3         
##  Max.   :48.00   Max.   :1.2400   Max.   :3
#2.subset of the columns and rows. Make sure to rename it
   Animal2<-subset(Animal,poison>=2 & treat=="D")
   Animal2
##     X time poison treat
## 41 41 0.56      2     D
## 42 42 1.02      2     D
## 43 43 0.71      2     D
## 44 44 0.38      2     D
## 45 45 0.30      3     D
## 46 46 0.36      3     D
## 47 47 0.31      3     D
## 48 48 0.33      3     D
#3.Create new column names for the new data frame
   colnames(Animal2)<-c("Number","TestTime","PoisonNumber","Treat")
    Animal2
##    Number TestTime PoisonNumber Treat
## 41     41     0.56            2     D
## 42     42     1.02            2     D
## 43     43     0.71            2     D
## 44     44     0.38            2     D
## 45     45     0.30            3     D
## 46     46     0.36            3     D
## 47     47     0.31            3     D
## 48     48     0.33            3     D
#4.Use the summary function to create an overview of your new data frame.Please compare
    summary(Animal2)
##      Number         TestTime       PoisonNumber Treat
##  Min.   :41.00   Min.   :0.3000   Min.   :2.0   A:0  
##  1st Qu.:42.75   1st Qu.:0.3250   1st Qu.:2.0   B:0  
##  Median :44.50   Median :0.3700   Median :2.5   C:0  
##  Mean   :44.50   Mean   :0.4963   Mean   :2.5   D:8  
##  3rd Qu.:46.25   3rd Qu.:0.5975   3rd Qu.:3.0        
##  Max.   :48.00   Max.   :1.0200   Max.   :3.0
#5.For at least 3 values in a column please rename so that every value in that column is renamed.
    Animal3<-as.data.frame(sapply(Animal,gsub,pattern="A",replacement="Special",ignore.case = TRUE))
    print(Animal3)
##     X time poison   treat
## 1   1 0.31      1 Special
## 2   2 0.45      1 Special
## 3   3 0.46      1 Special
## 4   4 0.43      1 Special
## 5   5 0.36      2 Special
## 6   6 0.29      2 Special
## 7   7  0.4      2 Special
## 8   8 0.23      2 Special
## 9   9 0.22      3 Special
## 10 10 0.21      3 Special
## 11 11 0.18      3 Special
## 12 12 0.23      3 Special
## 13 13 0.82      1       B
## 14 14  1.1      1       B
## 15 15 0.88      1       B
## 16 16 0.72      1       B
## 17 17 0.92      2       B
## 18 18 0.61      2       B
## 19 19 0.49      2       B
## 20 20 1.24      2       B
## 21 21  0.3      3       B
## 22 22 0.37      3       B
## 23 23 0.38      3       B
## 24 24 0.29      3       B
## 25 25 0.43      1       C
## 26 26 0.45      1       C
## 27 27 0.63      1       C
## 28 28 0.76      1       C
## 29 29 0.44      2       C
## 30 30 0.35      2       C
## 31 31 0.31      2       C
## 32 32  0.4      2       C
## 33 33 0.23      3       C
## 34 34 0.25      3       C
## 35 35 0.24      3       C
## 36 36 0.22      3       C
## 37 37 0.45      1       D
## 38 38 0.71      1       D
## 39 39 0.66      1       D
## 40 40 0.62      1       D
## 41 41 0.56      2       D
## 42 42 1.02      2       D
## 43 43 0.71      2       D
## 44 44 0.38      2       D
## 45 45  0.3      3       D
## 46 46 0.36      3       D
## 47 47 0.31      3       D
## 48 48 0.33      3       D
#6.Display enough rows to see examples of all of steps 1-5 above
    head(Animal3,15)
##     X time poison   treat
## 1   1 0.31      1 Special
## 2   2 0.45      1 Special
## 3   3 0.46      1 Special
## 4   4 0.43      1 Special
## 5   5 0.36      2 Special
## 6   6 0.29      2 Special
## 7   7  0.4      2 Special
## 8   8 0.23      2 Special
## 9   9 0.22      3 Special
## 10 10 0.21      3 Special
## 11 11 0.18      3 Special
## 12 12 0.23      3 Special
## 13 13 0.82      1       B
## 14 14  1.1      1       B
## 15 15 0.88      1       B
    tail(Animal3)
##     X time poison treat
## 43 43 0.71      2     D
## 44 44 0.38      2     D
## 45 45  0.3      3     D
## 46 46 0.36      3     D
## 47 47 0.31      3     D
## 48 48 0.33      3     D

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.