Saturday, June 25, 2016

R lab - Exploring data Coursera Solution provided here

Here is solution of R lab of r lab exploring data of Basic Statistics which is offer by the online coursera website
Its solution is given below you can 100% result in R lab experiment

Basic Statistics

R lab - Exploring data

Checking the dimensions of your data
Q1. #Use the dim() function on mtcars
Answer:- dim(mtcars) 
Data Structure
Q.2 According to R, what type of variable is am?
Answer factor



Q.3 # Look at the levels of the variable am

Answer  levels(mtcars$am)


Recoding Variables

Q #Assign the value of mtcars to the new variable mtcars2
mtcars2 <- mtcars
Q #Assign the label "high" to mpgcategory where mpg is greater than or equal to 20
mtcars2$mpgcategory[mtcars2$mpg >= 20] <- "high"
Q #Assign the label "low" to mpgcategory where mpg is less than 20
mtcars2$mpgcategory[mtcars2$mpg < 20] <- "low"
Q #Assign mpgcategory as factor to mpgfactor
mtcars2$mpgfactor <- as.factor(mtcars2$mpgcategory)

Examining Frequencies

Q #How many of the cars have a manual transmission?

Cumulative Frequency

Q # What percentage of cars have 3 or 5 gears?

Making a Bar Graph

Q #Assign the frequency of the mtcars variable "am" to a variable called "height"
height <- table(mtcars$am)
Q #Create a barplot of "height"

Labelling A Bar Graph

Q # vector of bar heights
height <- table(mtcars$am)
Q # Make a vector of the names of the bars called "barnames"
barnames <- c("automatic", "manual")
Q # Label the y axis "number of cars" and label the bars using barnames
barplot(height, ylab = "number of cars", names.arg = barnames)

Interpreting A Bar Graph

Q Based on the bar chart of transmission type that you made in the previous exercise, which type of transmission is most common? (remember, 0 = automatic, 1 = manual)



Q # Make a histogram of the carb variable from the mtcars data set. Set the title to "Carburetors"
hist(mtcars$carb, main = "Carburetors")

Formatting Your Histogram

Q # arguments to change the y-axis scale to 0 - 20, label the x-axis and colour the bars red
hist(mtcars$carb, main = "Carburetors", ylim = c(0,20), xlab = "Number of Carburetors", col = "red")

Bar Graph vs. Histogram

Bar Graph vs. Histogram

Why did we make a bar graph of transmission (mtcars$am), but a histogram of carburetors (mtcars$carb)

Possible Answers

Because transmission is categorical, and carb is continuous


Take a look at the distributions in these histograms. Which of the following is correct?

Possible Answers

Graph 1 is left skewed, graph 2 is normally distributed, graph 3 is right skewed.

Mean and Median

Q # Calculate the mean miles per gallon
Q # Calculate the median miles per gallon


# Produce a sorted frequency table of `carb` from `mtcars`
sort(table(mtcars$carb), decreasing = TRUE)


# Minimum value
x <- min(mtcars$mpg)
# Maximum value
y <- max(mtcars$mpg)
# Calculate the range of mpg using x and y
y – x


Q # What is the value of the second quartile?
Q # What is the value of the first quartile?

IQR and boxplot

Q # Make a boxplot of qsec
Q # Calculate the interquartile range of qsec

IQR outliers

Q # What is the threshold value for an outlier below the first quartile?
Q # What is the threshold value for an outlier above the third quartile?

Standard Deviation

Q # Find the IQR of horsepower
Q # Find the standard deviation of horsepower
Q # Find the IQR of miles per gallon
Q # Find the standard deviation of miles per gallon
Mean, median and mode.
Mean, median and mode are all measures of the average. In a perfect normal distribution the mean, median and mode values are identical, but when the data is skewed this changes. In the the graph on the right which of the following statements are most accurate?
The mode is higher than the mean. It makes most sense to use the median to measure central tendency.

Calculating Z-scores

# Calculate the z-scores of mpg
(mtcars$mpg - mean(mtcars$mpg)) / sd(mtcars$mpg)
Distributions And Z-scores
In the distribution shown on the right, what percentage of data will fall between the z-scores of -2 and 2?
95 %
Z-score Outliers
Outside of which boundaries might an observation be considered an outlier?
-3 and 3


  1. If you need your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (no matter why you broke up) you need to watch this video
    right away...

    (VIDEO) Get your ex back with TEXT messages?


    Get professional trading signals sent to your mobile phone daily.

    Follow our signals NOW & make up to 270% a day.