NurbekSakiev / R_Programming

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

R_Programming

Thank you. Your submission for this quiz was received.

You submitted this quiz on Sun 12 Apr 2015 1:40 AM PDT. You got a score of 20.00 out of 20.00.

###Introduction

This first quiz will check your ability to execute basic operations on objects in R and to understand some basic concepts. For questions 11–20 you will need to load a dataset into R and do some basic manipulations in order to answer the questions on the quiz.

You may want to print a copy of the quiz questions to look at as you work on the assignment. It is recommended that you save your answers as you go in the event that a technical problem should occur with your network connection or computer. Ultimately, you must submit the quiz online to get credit!

Data

The zip file containing the data for questions 11–20 in this Quiz can be downloaded here:

For this assignment you will need to unzip this file in your working directory.

<div class="course-quiz-question-body">

Question 1

R was developed by statisticians working at
Your Answer Score Explanation
The University of New South Wales
Insightful
The University of Auckland Correct 1.00 The R language was developed by Ross Ihaka and Robert Gentleman who were statisticians at the University of Auckland in New Zealand.
Microsoft
Total 1.00 / 1.00

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?
Your Answer Score Explanation
The freedom to restrict access to the source code for the software. Correct 1.00 This is not part of the free software definition. Freedoms 1 and 3 require access to the source code.
The freedom to improve the program, and release your improvements to the public, so that the whole community benefits.
The freedom to run the program, for any purpose.
The freedom to study how the program works, and adapt it to your needs.
Total 1.00 / 1.00

Question 3

In R the following are all atomic data types EXCEPT
Your Answer Score Explanation
character
integer
numeric
table Correct 1.00 'table' is not an atomic data type in R.
Total 1.00 / 1.00

Question 4

If I execute the expression x <- 4 in R, what is the class of the object `x' as determined by the `class()' function?
Your Answer Score Explanation
complex
vector
numeric Correct 1.00
real
Total 1.00 / 1.00

Question 5

What is the class of the object defined by the expression x <- c(4, "a", TRUE)?
Your Answer Score Explanation
character Correct 1.00 The character class is the "lowest common denominator" here and so all elements will be coerced into that class.
integer
mixed
numeric
Total 1.00 / 1.00
Question Explanation

R does automatic coercion of vectors so that all elements of the vector are the same data class.

Question 6

If I have two vectors x <- c(1,3, 5) and y <- c(3, 2, 10), what is produced by the expression rbind(x, y)?
Your Answer Score Explanation
a 3 by 3 matrix
a vector of length 2
a vector of length 3
a matrix with two rows and three columns Correct 1.00 The 'rbind' function treats vectors as if they were rows of a matrix. It then takes those vectors and binds them together row-wise to create a matrix.
Total 1.00 / 1.00

Question 7

A key property of vectors in R is that
Your Answer Score Explanation
the length of a vector must be less than 32,768
a vector cannot have have attributes like dimensions
elements of a vector can only be character or numeric
elements of a vector all must be of the same class Correct 1.00
Total 1.00 / 1.00

Question 8

Suppose I have a list defined as x <- list(2, "a", "b", TRUE). What does x[[2]] give me?
Your Answer Score Explanation
a list containing character vector with the letter "a".
a list containing a character vector with the elements "a" and "b".
a character vector with the elements "a" and "b".
a character vector containing the letter "a". Correct 1.00
Total 1.00 / 1.00

Question 9

Suppose I have a vector x <- 1:4 and y <- 2:3. What is produced by the expression x + y?
Your Answer Score Explanation
an integer vector with the values 3, 5, 5, 7. Correct 1.00
a numeric vector with the values 1, 2, 5, 7.
a warning
a numeric vector with the values 3, 5, 3, 4.
Total 1.00 / 1.00

Question 10

Suppose I have a vector x <- c(3, 5, 1, 10, 12, 6) and I want to set all elements of this vector that are less than 6 to be equal to zero. What R code achieves this?
Your Answer Score Explanation
x[x == 0]
x[x <= 5] <- 0 Correct 1.00 You can create a logical vector with the expression x <= 5 and then use the [ operator to subset the original vector x.
x[x > 0] <- 6
x[x == 6] <- 0
Total 1.00 / 1.00

Question 11

In the dataset provided for this Quiz, what are the column names of the dataset?
Your Answer Score Explanation
1, 2, 3, 4, 5, 6
Ozone, Solar.R, Wind, Temp, Month, Day Correct 1.00 You can get the column names of a data frame with the `names()' function.
Month, Day, Temp, Wind
Ozone, Solar.R, Wind
Total 1.00 / 1.00

Question 12

Extract the first 2 rows of the data frame and print them to the console. What does the output look like?
Your Answer Score Explanation
  Ozone Solar.R Wind Temp Month Day
1    41     190  7.4   67     5   1
2    36     118  8.0   72     5   2
Correct 1.00 You can extract the first two rows using the [ operator and an integer sequence to index the rows.
  Ozone Solar.R Wind Temp Month Day
1     7      NA  6.9   74     5  11
2    35     274 10.3   82     7  17
  Ozone Solar.R Wind Temp Month Day
1     9      24 10.9   71     9  14
2    18     131  8.0   76     9  29
  Ozone Solar.R Wind Temp Month Day
1    18     224 13.8   67     9  17
2    NA     258  9.7   81     7  22
Total 1.00 / 1.00

Question 13

How many observations (i.e. rows) are in this data frame?
Your Answer Score Explanation
160
129
153 Correct 1.00 You can use the `nrow()' function to compute the number of rows in a data frame.
45
Total 1.00 / 1.00

Question 14

Extract the last 2 rows of the data frame and print them to the console. What does the output look like?
Your Answer Score Explanation
    Ozone Solar.R Wind Temp Month Day
152    18     131  8.0   76     9  29
153    20     223 11.5   68     9  30
Correct 1.00 The `tail()' function is an easy way to extract the last few elements of an R object.
    Ozone Solar.R Wind Temp Month Day
152    34     307 12.0   66     5  17
153    13      27 10.3   76     9  18
    Ozone Solar.R Wind Temp Month Day
152    11      44  9.7   62     5  20
153   108     223  8.0   85     7  25
    Ozone Solar.R Wind Temp Month Day
152    31     244 10.9   78     8  19
153    29     127  9.7   82     6   7
Total 1.00 / 1.00

Question 15

What is the value of Ozone in the 47th row?
Your Answer Score Explanation
63
18
34
21 Correct 1.00 The single bracket [ operator can be used to extract individual rows of a data frame.
Total 1.00 / 1.00

Question 16

How many missing values are in the Ozone column of this data frame?
Your Answer Score Explanation
78
37 Correct 1.00
9
43
Total 1.00 / 1.00
Question Explanation

The `is.na' function can be used to test for missing values.

Question 17

What is the mean of the Ozone column in this dataset? Exclude missing values (coded as NA) from this calculation.
Your Answer Score Explanation
31.5
18.0
42.1 Correct 1.00
53.2
Total 1.00 / 1.00
Question 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?
Your Answer Score Explanation
212.8 Correct 1.00
185.9
205.0
334.0
Total 1.00 / 1.00
Question Explanation

You need to construct a logical vector in R to match the question's requirements. Then use that logical vector to subset the data frame.

Question 19

What is the mean of "Temp" when "Month" is equal to 6?
Your Answer Score Explanation
79.1 Correct 1.00
75.3
90.2
85.6
Total 1.00 / 1.00

Question 20

What was the maximum ozone value in the month of May (i.e. Month = 5)?
Your Answer Score Explanation
97
18
100
115 Correct 1.00
Total 1.00 / 1.00
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ config: ["MMLorHTML.js"], styleSheets: [], styles: {}, jax: ["input/TeX"], extensions: ["tex2jax.js"], preJax: null, postJax: null, preRemoveClass: "MathJax_Preview", showProcessingMessages: true, messageStyle: "none", displayAlign: "center", displayIndent: "0em", delayStartupUntil: "none", skipStartupTypeset: false, elements: [], tex2jax: { inlineMath: [ ['$$','$$'], // uncomment this for standard TeX math delimiters ['\\(','\\)'] ], displayMath: [ ['\\[','\\]'] ], skipTags: ["script","noscript","style","textarea","pre","code"], ignoreClass: "tex2jax_ignore", processClass: "tex2jax_process", processEscapes: false, processEnvironments: true, preview: "TeX" }, mml2jax: { preview: "alttext" }, jsMath2jax: { preview: "TeX" }, TeX: { TagSide: "right", TagIndent: ".8em", MultLineWidth: "85%", Macros: {}, extensions: ["AMSmath.js", "AMSsymbols.js"] }, //============================================================================ // // These parameters control the MathML inupt jax. // MathML: { // // This specifies whether to use TeX spacing or MathML spacing when the // HTML-CSS output jax is used. // useMathMLspacing: false }, //============================================================================ // // These parameters control the HTML-CSS output jax. // "HTML-CSS": { scale: 100, availableFonts: ["STIX","TeX"], preferredFont: "TeX", webFont: "TeX", imageFont: "TeX", undefinedFamily: "STIXGeneral,'Arial Unicode MS',serif", showMathMenu: true, styles: {}, tooltip: { delayPost: 600, // milliseconds delay before tooltip is posted after mouseover delayClear: 600, // milliseconds delay before tooltip is cleared after mouseout offsetX: 10, offsetY: 5 // pixels to offset tooltip from mouse position } }, //============================================================================ // // These parameters control the NativeMML output jax. // NativeMML: { scale: 100, showMathMenu: true, showMathMenuMSIE: true, styles: {} }, MathMenu: { delay: 400, helpURL: "http://www.mathjax.org/help/user/", showRenderer: true, showFontMenu: false, showContext: false, windowSettings: { status: "no", toolbar: "no", locationbar: "no", menubar: "no", directories: "no", personalbar: "no", resizable: "yes", scrollbars: "yes", width: 100, height: 50 }, styles: {} }, MMLorHTML: { prefer: { MSIE: "MML", Firefox: "HTML", Opera: "HTML", other: "HTML" } } }); </script> <script type="text/javascript"> (function () { function loadMathJax() { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "https://duqnjvq4jwr55.cloudfront.net/2.1/MathJax.js"; document.getElementsByTagName("head")[0].appendChild(script); } window.loadOrRefreshMathJax = function(domId) { if (window.MathJax) { if (domId) { MathJax.Hub.Queue(["Typeset", MathJax.Hub, domId]); } else { MathJax.Hub.Queue(["Typeset", MathJax.Hub]); } } else { loadMathJax(); } } })(); </script>

<script>document.getElementById("coursera-loading-js").style.display = 'block';</script><script>if (/zh/i.test(window.localStorage ? localStorage.getItem('locale') : '') || '{{ locale }}') {

document.getElementById('get-browser-zh').style.display = 'block'; }</script><script>document.getElementById('coursera-loading-js').style.display = 'block';</script> <script src='https://dw0ugk4msqulk.cloudfront.net/45a2e13c4a910d8569cd8a8a3f7f8565d720bcee/js/vendor/jquery.v1-7.js' ></script>

<script src="https://dw0ugk4msqulk.cloudfront.net/45a2e13c4a910d8569cd8a8a3f7f8565d720bcee/js/vendor/require.v2-1-1.js"></script><script data-baseurl="https://dw0ugk4msqulk.cloudfront.net/45a2e13c4a910d8569cd8a8a3f7f8565d720bcee/" data-version="45a2e13c4a910d8569cd8a8a3f7f8565d720bcee" data-timestamp='1428622243318' data-debug='0' data-locale="en_US" id="_require">if(document.getElementById('coursera-loading-js').style.display == 'block') {

(function(el) { require.config({ //enforceDefine: true, waitSeconds: 75, baseUrl: el.getAttribute('data-baseurl'), urlArgs: el.getAttribute('data-debug') == '1' ? 'v=' + el.getAttribute('data-timestamp') : '', shim: { 'underscore': { exports: '' }, 'backbone': { deps: ['underscore', 'jquery'], exports: 'Backbone', init: function(, $) { Backbone.$ = $; return Backbone; } }, 'pages/hg/thirdparty/js/backbone.marionette': { deps: ['backbone'] }, 'pages/hg/thirdparty/js/webshims/polyfiller': { deps: ['jquery'] }, 'pages/hg/thirdparty/js/webshims/extras/mousepress': { deps: ['jquery', 'pages/hg/thirdparty/js/webshims/polyfiller'] }, 'pages/hg/thirdparty/js/jquery.throttle': { deps: ['jquery'] }, 'js/lib/jquery.linkify': { deps: ['jquery'] }, 'pages/hg/thirdparty/js/js/bootstrap/alert': { deps: ['jquery', 'pages/hg/thirdparty/js/bootstrap/transition'] }, 'spark/core/js/jquery_ui': { deps: ['jquery'] }, 'spark/core/js/jquery.history': { deps: ['jquery'] }, 'js/lib/bootstrap.tooltip': { deps: ['jquery'] }, 'pages/hg/thirdparty/js/bootstrap/transition': { deps: ['jquery'] }, 'pages/hg/thirdparty/js/bootstrap/tab': { deps: ['jquery'] }, 'bundles/videojs/lib/video.4.3.0': { exports: 'vjs' } }, paths: { 'q': 'js/vendor/q.v1-0-1', 'react-with-addons': 'js/vendor/react-with-addons.v0-12', 'jquery': 'pages/spark/jquery', 'underscore': 'js/vendor/underscore.v1-5-2', 'backbone': 'js/vendor/backbone.v1-1-0', 'backbone.relational': 'js/lib/backbone.relational.0.8.6', 'i18n': 'js/lib/i18n._t', 'css': 'js/vendor/require.css.v0-1-2', 'memoize': 'js/lib/require.memoize.v0-0-1', 'pages/spark/models/user.json': 'empty:', 'pages/spark/models/course.json': 'empty:', 'pages/spark/models/navbar.json': 'empty:' }, callback: function() { require(['pages/spark/routes']); }, config: { i18n: { locale: (window.localStorage ? localStorage.getItem('locale') : '') || el.getAttribute('data-locale') } } }); })(document.getElementById('_require')); } </script><script>define('pages/spark/models/user.json', [], function(){ return JSON.parse("{"id":857781,"email_address":"sakin.snn@gmail.com","full_name":"Nurbek","locale":"en_US","timezone":"America\/Los_Angeles","access_group_id":"4","registration_time":"1428135765","last_access_time":"1428826120","last_access_ip":"50.153.232.3","signature_track_register_time":"1428135765","email_announcement":"1","email_forum":"1","in_signature_track":"1","wishes_proctored_exam":null,"first_name":"Nurbek","permissions":["default","allow_site_access"],"group":"Student","anonymous":false,"forum_title":"Student","signature_track_state":4,"verified_quizzes":["97"],"submitted_quizzes":["97"],"scheduled_proctored_exam":null,"last_chance_modal":null,"flexjoin_last_chance_modal":null}"); }); define('pages/spark/models/course.json', [], function(){ return JSON.parse("{"id":973494,"isPrivate":false,"type":"public","name":"R Programming","instructor":"Roger D. Peng, PhD, Jeff Leek, PhD, Brian Caffo, PhD","sessionName":"rprog-013","externalBaseURL":"https:\/\/www.coursera.org\/","shortname":"rprog","host":"https:\/\/www.coursera.org\/","assetUnversionedLink":"https:\/\/dw0ugk4msqulk.cloudfront.net\/","cheggID":"","hasLTI":true,"badgevilleDomain":"","linkable":false,"universityShortname":"jhu","signatureTrackStatus":{"signature_track_enabled":1,"signature_track_duration_left":"4 days and 15 hours","signature_track_duration_left_days":"4 days","signature_track_sign_up_now":1,"signature_track_last_chance_dialog":1,"flexjoin_last_chance_dialog":0},"courseURLs":{"log_in_link":"https:\/\/www.coursera.org\/login?post_redirect=https%3A%2F%2Fwww.coursera.org%2Flogin%3Fuser_action%3Dclass%26course_id%3D973494%26post_redirect%3Dhttps%253A%252F%252Fclass.coursera.org%252Frprog-013%252Fauth%252Fauth_redirector%253Ftype%253Dlogin%2526subtype%253Dnormal%2526visiting%253D","sign_up_link":"https:\/\/www.coursera.org\/signup?enroll_cid=973494&enroll_sn=rprog&enroll_n=R Programming","view_course_info_link":"https:\/\/www.coursera.org\/course\/rprog","sign_up_link_cant_enroll":"https:\/\/www.coursera.org\/signup?post_redirect=https%3A%2F%2Fwww.coursera.org%2Fcourse%2Frprog"},"courseBase":"https:\/\/class.coursera.org\/rprog-013\/","search":true,"hideWiki":true,"aceStartRegistrationDate":"Wed 31 Dec 1969 4:00 PM PST","aceEndRegistrationDate":"Wed 31 Dec 1969 4:00 PM PST","aceExamStartDate":"Wed 31 Dec 1969 4:00 PM PST","aceExamEndDate":"Wed 31 Dec 1969 4:00 PM PST","aceExamRules":"","aceExamDuration":"","aceBeforeExam":false,"aceAfterExam":true,"aceHours":null,"aceCreditType":"","acePrice":null,"aceExamID":null,"aceEligible":false,"canRegisterForACE":false,"specialization":{"numCourse":9,"image":"https:\/\/s3.amazonaws.com\/coursera\/specializations\/jhudatascience\/logo_small.png","id":1,"short_name":"jhudatascience","name":"Data Science"},"supportForums":true,"textbooks":"","inVideoQuizV2":false,"in_flexjoin":0,"honorCodeExtraText":"","honorCodeCustomTitle":"","honorCodeCustomButton":"","studentAccessDisabled":0,"disableQQs":false}"); }); define('pages/spark/models/navbar.json', [], function(){ return JSON.parse("{"items":[{"name":"Announcements","icon":"","link_type":"circuit","link_data":"class:index"},{"name":"Week-by-Week","icon":"","link_type":"heading","link_data":""},{"name":"Week 1: Getting Started and R Nuts and Bolts","icon":"home","link_type":"wiki","link_data":"Week_1"},{"name":"Week 2: Programming with R","icon":"lecture","link_type":"wiki","link_data":"Week_2"},{"name":"Week 3: Loop Functions and Debugging","icon":"forum","link_type":"wiki","link_data":"Week_3"},{"name":"Week 4: Simulation and Profiling","icon":"","link_type":"wiki","link_data":"Week_4"},{"name":"Lectures","icon":"","link_type":"heading","link_data":""},{"name":"Lecture Videos","icon":"","link_type":"circuit","link_data":"lecture:index"},{"name":"Lecture Slides (link to GitHub)","icon":"","link_type":"window_link","link_data":"https:\/\/github.com\/rdpeng\/courses\/tree\/master\/02_RProgramming"},{"name":"Exercises","icon":"","link_type":"heading","link_data":""},{"name":"Quizzes","icon":"quiz","link_type":"circuit","link_data":"quiz:index"},{"name":"Programming Assignments 1, 3, & swirl","icon":"assignment","link_type":"circuit","link_data":"assignment:index"},{"name":"Programming Assignment 2","icon":"assignment","link_type":"circuit","link_data":"human_grading:index"},{"name":"","icon":"","link_type":"circuit","link_data":""},{"name":"About the course","icon":"","link_type":"heading","link_data":""},{"name":"Syllabus","icon":"wiki","link_type":"wiki","link_data":"syllabus"},{"name":"About the Instructor","icon":"","link_type":"wiki","link_data":"About_the_Instructor"},{"name":"Community","icon":"","link_type":"heading","link_data":""},{"name":"DSS Community Site","icon":"","link_type":"window_link","link_data":"http:\/\/datasciencespecialization.github.io\/"},{"name":"Discussion Forums","icon":"","link_type":"circuit","link_data":"forum:index"}]}"); }); </script><script>var coursera_enable_new_help_center = true; </script>

About


Languages

Language:R 100.0%