- Coursera: R programming Week 2 Assignment
- by Lingyun Gao
- Last updated over 7 years ago
- Hide Comments (–) Share Hide Toolbars
Twitter Facebook Google+
Or copy & paste this link into an email or IM:
Instantly share code, notes, and snippets.
mGalarnyk / quiz1.md
- Download ZIP
- Star ( 23 ) 23 You must be signed in to star a gist
- Fork ( 38 ) 38 You must be signed in to fork a gist
- Embed Embed this gist in your website.
- Share Copy sharable link for this gist.
- Clone via HTTPS Clone using the web URL.
- Learn more about clone URLs
- Save mGalarnyk/972074f79957940eec765b216d526484 to your computer and use it in GitHub Desktop.
R Programming Quiz 1 (JHU) Coursera
github repo for rest of specialization: Data Science Coursera
R was developed by statisticians working at...
The University of Auckland
The definition of free software consists of four freedoms (freedoms 0 through 3). Which of the following is NOT one of the freedoms that are part of the definition?
The freedom to sell the software for any price.
In R the following are all atomic data types EXCEPT
If I execute the expression x <- 4 in R, what is the class of the object 'x' as determined by the `class()' function?
What is the class of the object defined by x <- c(4, TRUE)?
If I have two vectors x <- c(1,3, 5) and y <- c(3, 2, 10), what is produced by the expression cbind(x, y)?
a 3 by 2 numeric matrix
A key property of vectors in R is that
elements of a vector all must be of the same class
Suppose I have a list defined as x <- list(2, "a", "b", TRUE). What does x[[1]] give me?
a numeric vector containing the element 2
Suppose I have a vector x <- 1:4 and a vector y <- 2. What is produced by the expression x + y?
a numeric vector with elements 3, 4, 5, 6.
Question 10
Suppose I have a vector x <- c(17, 14, 4, 5, 13, 12, 10) and I want to set all elements of this vector that are greater than 10 to be equal to 4. What R code achieves this?
x[x >= 11] <- 4
Question 11
In the dataset provided for this Quiz, what are the column names of the dataset?
Ozone, Solar.R, Wind, Temp, Month, Day
Question 12
Extract the first 2 rows of the data frame and print them to the console. What does the output look like?
Question 13
How many observations (i.e. rows) are in this data frame?
Question 14
Extract the last 2 rows of the data frame and print them to the console. What does the output look like?
Question 15
What is the value of Ozone in the 47th row?
Question 16
How many missing values are in the Ozone column of this data frame?
Question 17
What is the mean of the Ozone column in this dataset? Exclude missing values (coded as NA) from this calculation.
Explanation
The 'mean' function can be used to calculate the mean.
Question 18
Extract the subset of rows of the data frame where Ozone values are above 31 and Temp values are above 90. What is the mean of Solar.R in this subset?
Question 19
What is the mean of "Temp" when "Month" is equal to 6?
Question 20
What was the maximum ozone value in the month of May (i.e. Month = 5)?
Armbarbarian commented Apr 26, 2020
Thanks for this, so helpful. The course didn't go through a lot of the above code
Sorry, something went wrong.
Munim2001 commented May 4, 2020
Thank you so much for your help
Rgill800 commented May 7, 2020
Incredibly helpful
lekanfaye commented May 15, 2020
Thanks for your help, the 2nd part is not covered in the lecture
Arunan-R commented May 26, 2020
Thanks for the help. I went through the coursework twice but couldnt find how to do operations on the columns of the tables, This was very helpful!
Wainaina16 commented Jul 14, 2020
Thanks for the help
stocke777 commented Jul 18, 2020
coding part is right but not all
elbobbyjose commented Jul 24, 2020
Thanks my friend!
yashg008 commented Jul 28, 2020
thank you so much
omarabdelaz1z commented Aug 15, 2020
Very Helpful and kinda new commands for me, Thank you.
Dizartx commented Aug 17, 2020
DrDoofenshmirz commented Aug 26, 2020
thank u so much . some of the questions in the quiz require code that hasn't been taught yet in the course
Willto884 commented Sep 2, 2020
Very helpful... thank u very much...!
mastep25 commented Oct 10, 2020
Thank you very much for this help. You really contributed to my pass mark. Thanks
Sakshamgoel commented Dec 14, 2020
A big help to all who don't wanna buy the course but still want to learn.
jhw3 commented Jun 11, 2021
apply(sub, 2, max) what does the 2 represent in this?
sarahguagliardo commented Jun 23, 2021
I'm not entirely sure how to use the "apply" function yet, but I was able to get the same answers using commands like >mean(sub$Temp) after creating the subset correctly. The course doesn't go over the correct format for subsetting data very well so this quiz was really hard!
GarimaSodhi commented Jul 4, 2021
Thank you so much. This quiz was hard.
nizburfat commented Sep 15, 2021
Rating, Cocoa.Percent, and Company.Location. You decide to use the select() function to create a new data frame with only these three variables.
Assume the first part of your code is:
trimmed_flavors_df <- flavors_df %>%
Add the code chunk that lets you select the three variables.
trimmed_flavors_df %>%
You want to use the summarize() and mean() functions to find the mean rating for your data. Add the code chunk that lets you find the mean value for the variable Rating.
michaeladams01 commented Nov 17, 2021 • edited Loading
This came in so clutch. Thank you sir.
Krispeta commented Feb 9, 2022
I was so confused, looking everywhere, going back on the book and lessons, until I had to look for this! thank you, you saved the day, I was going bananas!!
bikrammajhi commented Oct 12, 2022 • edited Loading
Thank you for helping me out in my assignment. I initially panic since the question answer were not there in videos.
Divyam6969 commented Aug 31, 2023
thank youuu, this quiz was way tooo long lol
- Show All Code
- Hide All Code
- Download Rmd
R Programming Week 2: Assignment 1
Initialisation.
Configure evironment
The function ‘pollutantmean’ calculates the mean of a pollutant (sulfate or nitrate) across a specified list of monitors. The function ‘pollutantmean’ takes three arguments: ‘directory’, ‘pollutant’, and ‘id’. Given a vector monitor ID numbers, ‘pollutantmean’ reads that monitors’ particulate matter data from the directory specified in the ‘directory’ argument and returns the mean of the pollutant across all of the monitors, ignoring any missing values coded as NA.
The function ‘complete’ reads a directory full of files and reports the number of completely observed cases in each data file. The function should return a data frame where the first column is the name of the file and the second column is the number of complete cases.
The function ‘corr’ takes a directory of data files and a threshold for complete cases and calculates the correlation between sulfate and nitrate for monitor locations where the number of completely observed cases (on all variables) is greater than the threshold. The function should return a vector of correlations for the monitors that meet the threshold requirement. If no monitors meet the threshold requirement, then the function should return a numeric vector of length 0.
Q1. What value is returned by the following call to pollutantmean()? You should round your output to 3 digits.
Q2. What value is returned by the following call to pollutantmean()? You should round your output to 3 digits.
Q3. What value is returned by the following call to pollutantmean()? You should round your output to 3 digits.
Q4. What value is returned by the following call to pollutantmean()? You should round your output to 3 digits.
Q5. What value is printed at end of the following code?
Q6. What value is printed at end of the following code?
Q7. What value is printed at end of the following code?
Q8. What value is printed at end of the following code?
Q9. What value is printed at end of the following code?
Q10. What value is printed at end of the following code?
IMAGES
VIDEO
COMMENTS
Coursera - Course 2 - Week 2 - Assignment 1 - R Programming. This repository contains the solutions that I used for Coursera's Data Science Assignment 1 for Week 2 in Course 2. The dataset is provided as a zip file called "specdata.zip". The dataset can be downloaded from the course.
R Programming by Johns Hopkins University - Week 2 - Assignment 1. Part 1. A function named 'pollutantmean' that calculates the mean of a pollutant (sulfate or nitrate) across a specified list of monitors. The function takes three arguments: 'directory', 'pollutant', and 'id'.
This is the week 2 programming assignment from the Coursera R Programming course in the Data Science Specialization from Johns Hopkins. This assignment is done in Python instead of R.
RPubs - Coursera: R programming Week 2 Assignment. R Pubs. by RStudio. Sign in Register. Coursera: R programming Week 2 Assignment. by Lingyun Gao. Last updated over 7 years ago. Comments (–) Share.
Coursera - R Programming: Week 2 Assignment 1 Walkthrough Part 2 (complete function) - YouTube. 0:00 / R Beginner Book...
For this first programming assignment you will write three functions that are meant to interact with dataset that accompanies this assignment. The dataset is contained in a zip file specdata.zip that you can download from the Coursera web site.
Question 1. Suppose I define the following function in R. cube <- function (x, n) { x^3 . } What is the result of running cube (3) in R after defining this function? Answer. The number 27 is returned. Question 2. The following code will produce a warning in R. x <- 1:10 if (x > 5) { x <- 0 . } Why? Answer.
Part 1. Write a function named ‘pollutantmean’ that calculates the mean of a pollutant (sulfate or nitrate) across a specified list of monitors. The function ‘pollutantmean’ takes three arguments: ‘directory’, ‘pollutant’, and ‘id’.
Question 1. R was developed by statisticians working at... Answer. The University of Auckland. Question 2. The definition of free software consists of four freedoms (freedoms 0 through 3). Which of the following is NOT one of the freedoms that are part of the definition? Answer. The freedom to sell the software for any price. Question 3.
Initialisation. Configure evironment. rm (list = ls ()) setwd ("~/OneDrive/datasciencecoursera/R_Programming/week2") The function ‘pollutantmean’ calculates the mean of a pollutant (sulfate or nitrate) across a specified list of monitors. The function ‘pollutantmean’ takes three arguments: ‘directory’, ‘pollutant’, and ‘id’.