data <- read.csv("https://raw.githubusercontent.com/mkollontai/R_HW_2/master/possum_data.csv")

1) Use the summary function to gain an overview of the data set. Then display the mean and median for at least two attributes

Summary <- summary(data)
Summary
##        X           case             site          Pop     sex   
##  A1     : 1   Min.   :  2.00   Min.   :1.000   other:19   f:43  
##  A2     : 1   1st Qu.: 18.00   1st Qu.:1.000   Vic  :24         
##  A4     : 1   Median : 40.00   Median :2.000                    
##  BB17   : 1   Mean   : 43.42   Mean   :2.977                    
##  BB31   : 1   3rd Qu.: 64.50   3rd Qu.:5.000                    
##  BB33   : 1   Max.   :104.00   Max.   :7.000                    
##  (Other):37                                                     
##       age           hdlngth          skullw         totlngth    
##  Min.   :1.000   Min.   :84.70   Min.   :51.50   Min.   :75.00  
##  1st Qu.:3.000   1st Qu.:90.75   1st Qu.:55.20   1st Qu.:85.25  
##  Median :4.000   Median :92.50   Median :56.40   Median :88.50  
##  Mean   :3.977   Mean   :92.15   Mean   :56.59   Mean   :87.91  
##  3rd Qu.:5.000   3rd Qu.:93.80   3rd Qu.:57.65   3rd Qu.:90.50  
##  Max.   :9.000   Max.   :96.90   Max.   :67.70   Max.   :96.50  
##                                                                 
##      taill          footlgth        earconch          eye       
##  Min.   :32.00   Min.   :60.30   Min.   :40.30   Min.   :13.00  
##  1st Qu.:36.00   1st Qu.:64.85   1st Qu.:44.65   1st Qu.:14.10  
##  Median :37.50   Median :70.45   Median :50.80   Median :14.80  
##  Mean   :37.10   Mean   :69.11   Mean   :48.58   Mean   :14.81  
##  3rd Qu.:38.25   3rd Qu.:72.80   3rd Qu.:52.30   3rd Qu.:15.45  
##  Max.   :41.00   Max.   :77.90   Max.   :53.90   Max.   :17.40  
##                  NA's   :1                                      
##      chest           belly      
##  Min.   :23.00   Min.   :25.00  
##  1st Qu.:26.00   1st Qu.:31.25  
##  Median :28.00   Median :33.00  
##  Mean   :27.34   Mean   :32.88  
##  3rd Qu.:28.50   3rd Qu.:34.00  
##  Max.   :31.00   Max.   :40.00  
## 
#eye
eyeMean <- 14.81
eyeMedian <- 14.80

#taill
taillMean <- 37.10
taillMedian <- 37.50

2) Create a new data frame with a subset of the columns and rows. Make sure to rename it

IncludeCol <- c("case","age","taill","eye","belly","sex")
IncludeRow <- c(1:10)
myPosD <- data[IncludeRow, IncludeCol]

3) Create new column names for the new data frame.

names(myPosD)[names(myPosD) == "case"] <- "Case"
names(myPosD)[names(myPosD) == "age"] <- "Age"
names(myPosD)[names(myPosD) == "taill"] <- "Tail_Length"
names(myPosD)[names(myPosD) == "eye"] <- "EyeSize"
names(myPosD)[names(myPosD) == "belly"] <- "BellySize"
names(myPosD)[names(myPosD) == "sex"] <- "Gender"
myPosD
##    Case Age Tail_Length EyeSize BellySize Gender
## 1     2   6        36.5    16.0        33      f
## 2     3   6        39.0    15.5        34      f
## 3     4   6        38.0    15.2        34      f
## 4     5   2        36.0    15.1        33      f
## 5     6   1        35.5    14.2        32      f
## 6     8   6        37.0    14.5        34      f
## 7     9   9        37.0    15.5        33      f
## 8    10   6        37.5    14.4        32      f
## 9    11   9        39.0    14.9        34      f
## 10   12   5        35.5    15.3        33      f

4) Use the summary function to create an overview of your new data frame. Then print the mean and median for the same two attributes. Please compare.

summary(myPosD)
##       Case            Age        Tail_Length       EyeSize     
##  Min.   : 2.00   Min.   :1.00   Min.   :35.50   Min.   :14.20  
##  1st Qu.: 4.25   1st Qu.:5.25   1st Qu.:36.12   1st Qu.:14.60  
##  Median : 7.00   Median :6.00   Median :37.00   Median :15.15  
##  Mean   : 7.00   Mean   :5.60   Mean   :37.10   Mean   :15.06  
##  3rd Qu.: 9.75   3rd Qu.:6.00   3rd Qu.:37.88   3rd Qu.:15.45  
##  Max.   :12.00   Max.   :9.00   Max.   :39.00   Max.   :16.00  
##    BellySize    Gender
##  Min.   :32.0   f:10  
##  1st Qu.:33.0         
##  Median :33.0         
##  Mean   :33.2         
##  3rd Qu.:34.0         
##  Max.   :34.0
#EyeSize
EyeSizeMean <- 15.06 
EyeSizeMedian <- 15.15

#Tail_Length
Tail_LengthMean <- 37.10
Tail_LengthMedian <- 37.00

CompareVal <- function(a,b){
  if (a > b)
  {
   Comp <- "lower than"
  } else
    {
      if (a == b) 
      {
        Comp <- "the same as"
      } else
      {
        Comp <- "higher than"
      }
    }
  return(Comp)
}  
sprintf("Subset's eye size mean is %s original data", CompareVal(eyeMean,EyeSizeMean))
## [1] "Subset's eye size mean is higher than original data"
sprintf("Subset's eye size median is %s original data", CompareVal(eyeMedian,EyeSizeMedian))
## [1] "Subset's eye size median is higher than original data"
sprintf("Subset's tail length mean is %s original data", CompareVal(taillMean,Tail_LengthMean))
## [1] "Subset's tail length mean is the same as original data"
sprintf("Subset's tail length median is %s original data", CompareVal(taillMean,Tail_LengthMedian))
## [1] "Subset's tail length median is lower than original data"

5) For at least 3 values in a column please rename so that every value in that column is renamed.

myPosD <- transform(myPosD, Gender = ifelse(myPosD$Gender == "f", Gender <- "Female",Gender <- "Male"))

6) Display enough rows to see examples of all of steps 1-5 above.

myPosD[1:5,]
##   Case Age Tail_Length EyeSize BellySize Gender
## 1    2   6        36.5    16.0        33 Female
## 2    3   6        39.0    15.5        34 Female
## 3    4   6        38.0    15.2        34 Female
## 4    5   2        36.0    15.1        33 Female
## 5    6   1        35.5    14.2        32 Female