# Question: here we create a vector called data1 which stores...

###### Question details

# Here we create a vector called Data1 which stores our dataset.

# "c" stands for concatenate or put together and lets the computer know to store all the data as a single vector

Data1<-c(1,3,3,3,4,7,10,11,12,22)

# We now find the mean of Data1 and store it in Data1.mean

Data1.mean<- mean(Data1)

#What happend when we have missing values?

Data2<-c(NA,Data1,NA)

#This command prints Data2 in our console

print(Data2)

#note that in this version of R, this command automaticlly supresses missing values.

#For older versions this is not the case.

Data2.mean<- mean(Data1)

# Find the median of Data1.

Data1.Median <- median(Data1)

#QUESTION 1: WHY IS THE MEDIAN NOT IN THE DATASET?

#QUESTION 2: HOW SHOULD WE COMPUTE THE MEDIAN IN THIS CASE?

##The following function estimates mode.R does not have a built in function to find mode.

MODE <- function(x, na.rm = FALSE) {## na.rm=FALSE supresses NA values

if(na.rm){

x = x[!is.na(x)]

}

ux <- unique(x)

return(ux[which.max(tabulate(match(x, ux)))])

}

# With the above function, we can call mode

Data1.Mode<-MODE(Data1)

print(Data1.Mode)

#QUESTION 3: Find a numerical dataset with at least 35 values. Use R to compute the mean, mode and median.