R Programming Basics Quiz
48 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What does the round() function do when applied to a vector?

  • Multiplies each element by 2
  • Rounds each element individually to the nearest integer (correct)
  • Returns the largest element in the vector
  • Calculates the average of the elements
  • In R, scalars are treated as single-element vectors.

    True

    What is the result of applying the function round() to the number 1.2?

    1

    The function f(x, c) returns the value of (x + c) ________.

    <p>squared</p> Signup and view all the answers

    Match the R function with its description:

    <p>round() = Rounds to the nearest integer sqrt() = Calculates the square root f(x,c) = Returns (x+c)^2 recycling = Extending a shorter vector to match a longer one</p> Signup and view all the answers

    What happens when you try to call the function f() with a vector as the second argument?

    <p>It results in an error</p> Signup and view all the answers

    The + operator in R is treated as a function.

    <p>True</p> Signup and view all the answers

    What is the expected output of the function f(1:3, 1)?

    <p>4 9 16</p> Signup and view all the answers

    What is the main purpose of the subset() function in R?

    <p>To handle NA values automatically</p> Signup and view all the answers

    The which() function in R returns the values that satisfy a given condition.

    <p>False</p> Signup and view all the answers

    What does the filtering expression x[x > 5] return if x contains NA values?

    <p>It returns the values greater than 5, including NA where applicable.</p> Signup and view all the answers

    The function used to identify the positions within a vector where a condition holds is called _____ function.

    <p>which</p> Signup and view all the answers

    Match the R operation with its output:

    <p>z[c(TRUE,FALSE,TRUE,TRUE)] = Extracts elements based on TRUE/FALSE x[x &gt; 5] = Returns values greater than 5 with NA included subset(x, x &gt; 5) = Returns values greater than 5 without NA which(z*z &gt; 8) = Returns indices of values that satisfy the condition</p> Signup and view all the answers

    What does the code first1 <- x[ifelse(x > 6, 2*x, 3*x)] evaluate?

    <p>It creates a vector with elements multiplied conditionally</p> Signup and view all the answers

    The result of the expression z * z > 8 is a vector of Boolean values.

    <p>True</p> Signup and view all the answers

    What is the advantage of using ifelse() over traditional if-then-else constructs in R?

    <p>It is vectorized and potentially much faster.</p> Signup and view all the answers

    What does the expression x[j,] return?

    <p>Rows of x specified by the true elements of j</p> Signup and view all the answers

    The operation of filtering rows using a Boolean vector is not vectorized.

    <p>False</p> Signup and view all the answers

    What operator is used for calculating the logical AND of two Boolean vectors in R?

    <p>&amp;</p> Signup and view all the answers

    The command z <- x[z %% 2 == 1,] extracts rows of x where the elements of z are ___ numbers.

    <p>odd</p> Signup and view all the answers

    What does the function drop do when applied in data operations?

    <p>It retains the two-dimensional nature of data.</p> Signup and view all the answers

    Using && will yield the same result as using & for logical operations on vector elements.

    <p>False</p> Signup and view all the answers

    If we apply the expression m[m[,1] > 1 & m[,2] > 5,], what type of rows are extracted from m?

    <p>Rows where the first column is greater than 1 and the second column is greater than 5.</p> Signup and view all the answers

    Match the following commands with their functionalities:

    <p>j &lt;- x[,2] &gt;= 3 = Identifies which elements in column 2 are at least equal to 3 z &lt;- x[z %% 2 == 1,] = Extracts rows with odd values in z m[m[,1] &gt; 1 &amp; m[,2] &gt; 5,] = Extracts rows based on multiple conditions drop = TRUE = Retains the two-dimensional structure of data</p> Signup and view all the answers

    What function is used to add columns to a matrix in R?

    <p>cbind()</p> Signup and view all the answers

    The rbind() function can be used to add rows to an existing matrix.

    <p>True</p> Signup and view all the answers

    What happens to the original matrix when you reassign a new matrix to it?

    <p>The original matrix is replaced and no longer exists.</p> Signup and view all the answers

    Using the cbind() function allows you to bind a column of ______ to the existing matrix.

    <p>values</p> Signup and view all the answers

    When creating a matrix in a loop, it is more efficient to:

    <p>Allocate a large matrix first.</p> Signup and view all the answers

    Match the function to its description:

    <p>rbind() = Combines rows of matrices cbind() = Combines columns of matrices matrix() = Creates a new matrix dim() = Returns the dimensions of a matrix</p> Signup and view all the answers

    What is the time penalty mentioned when repeatedly creating a matrix?

    <p>Time taken to allocate memory each time a new matrix is created.</p> Signup and view all the answers

    In R, using the function ______() allows for the recycling of values when creating a new matrix.

    <p>cbind</p> Signup and view all the answers

    What type of data structure is suggested for storing employee information?

    <p>List</p> Signup and view all the answers

    The numerical indices of list components must always be used when accessing data in a list.

    <p>False</p> Signup and view all the answers

    What Boolean value indicates that an employee is a member of a union?

    <p>TRUE</p> Signup and view all the answers

    To access a specific component of a list by name, you can use the syntax j$______.

    <p>salary</p> Signup and view all the answers

    Which of the following methods can be used to access the salary component of a list named j?

    <p>All of the above</p> Signup and view all the answers

    Match the following methods of accessing list components with their descriptions:

    <p>lst$c = Accessing component by name using dollar sign lst[[&quot;c&quot;]] = Accessing component by name using double brackets lst[[i]] = Accessing component by numerical index lst[&quot;c&quot;] = Accessing component by name returning a sublist</p> Signup and view all the answers

    Using single brackets to access a list component returns an element in the original data type.

    <p>False</p> Signup and view all the answers

    What is the advantage of using names instead of numerical indices in lists?

    <p>Clarity and less chance of error</p> Signup and view all the answers

    What type of vector is the result of using unlist() on the list containing the values "Joe", "55000", and "TRUE"?

    <p>Character vector</p> Signup and view all the answers

    The unlist() function will always return a numeric vector if the original list contains numeric values.

    <p>False</p> Signup and view all the answers

    What function is used to concatenate lists in R, which also includes an option for recursive flattening?

    <p>c()</p> Signup and view all the answers

    In R, when using the function unlist(), the components of the list are coerced to a common mode, typically resulting in a ____________ vector.

    <p>character</p> Signup and view all the answers

    Match the following terms with their descriptions:

    <p>unlist() = Converts a list to a vector c() = Concatenates objects length() = Returns the number of components recursive = Option for flattening lists during concatenation</p> Signup and view all the answers

    What is the result of calling the c() function with the recursive argument set to TRUE on a list where the components themselves are lists?

    <p>A single flattened list</p> Signup and view all the answers

    When combining lists, the default value for the recursive argument in the c() function is TRUE.

    <p>False</p> Signup and view all the answers

    What type does R choose when mixing numeric and character types in a list during unlist()?

    <p>character</p> Signup and view all the answers

    Study Notes

    Syllabus

    • R Programming is a course for III B.Sc CSDA students.
    • The course is for Semester V.
    • Syllabus includes 5 units covering R programming, data structures, operations, data frames, modeling, and classes & objects.

    Unit I

    • Introducing R: Introduction to R, R data structures, functions in R, vectors, scalars, declarations, recycling, vectorized operations, NA and NULL values, filtering, and vector element names.
    • Features of R Programming: Open-source, strong graphical capabilities, highly active community, a wide selection of packages, comprehensive environment, complex statistical calculations, distributed computing, running code without a compiler, interfacing with databases, data variety, machine learning, and data wrangling. Cross-platform support and compatibility with other programming languages are also noted.

    Unit II

    • Matrices and Operations: Creating matrices, matrix operations, applying functions to matrix rows and columns, adding and deleting rows/columns, vector/matrix distinction, avoiding dimension reduction, higher dimensional arrays, lists, creating lists, general list operations, accessing list components, values, applying functions to lists, and recursive lists.

    Unit III

    • Data Frames: Creating data frames, matrix- operations in frames, merging data frames, applying functions to data frames, factors, tables, factors and levels, common functions used with factors, working with tables, other factors and table-related functions, control statements, arithmetic and Boolean operators, default values for arguments, returning Boolean values, Functions are objects, environment and scope issues, writing upstairs, recursion, replacement functions, tools for composing function code, math and simulation in R.

    Unit IV

    • Classes and Objects: S3 and S4 classes, managing objects, input/output, accessing keyboard and monitor, reading and writing files, accessing the internet, string manipulation, graphics, creating graphs, customizing graphs, saving graphs, and creating three-dimensional plots.

    Unit V

    • Interfacing R to other languages, Parallel R, basic statistics, linear model, generalized linear models, non-linear models, time series, and autocorrelation, clustering.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    R Programming Syllabus PDF

    Description

    Test your knowledge of fundamental R programming concepts, including functions like round(), operator usage, and vector handling. This quiz covers various aspects of R syntax and functionality, providing a comprehensive overview for beginners.

    More Like This

    C Programming Functions Quiz
    5 questions
    C Programming Functions Quiz
    12 questions
    C Programming Functions Quiz
    5 questions
    MATLAB: Functions, Vectors, and Equations
    5 questions
    Use Quizgecko on...
    Browser
    Browser