R Programming Basics

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which data type is most suitable for storing whole numbers in R?

  • character
  • logical
  • numeric
  • integer (correct)

Given the R code x <- 5; if(x > 3) { print("Greater than 3") } else { print("Less than or equal to 3") }, what will be the output?

  • TRUE
  • Greater than 3 (correct)
  • FALSE
  • Less than or equal to 3

Which function efficiently generates a sequence of numbers in R?

  • list()
  • seq() (correct)
  • rep()
  • c()

What is the result of length(c(1, 2, 3, 4, 5))?

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

If my_matrix is a matrix, how do you correctly access the element in the 3rd row and 2nd column?

<p>my_matrix[3, 2] (A)</p> Signup and view all the answers

Which option is not a fundamental data structure in R?

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

Which function is the standard way to import data from a CSV file into R?

<p>read.csv() (D)</p> Signup and view all the answers

What does the $ operator accomplish in R?

<p>To access elements within a list or data frame by name (D)</p> Signup and view all the answers

Which function provides a concise overview of the structure of an R object?

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

What is the result of the modulo operation 10 %% 3 in R?

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

How should you install a new package in R?

<p>install.packages() (B)</p> Signup and view all the answers

What is the primary function of library() in R?

<p>To load and attach a package (B)</p> Signup and view all the answers

Which of the following represents a valid logical operator in R?

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

What is the result of the logical operation TRUE && FALSE in R?

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

Which function is specifically used to create a factor variable in R?

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

What is the outcome of running tolower("HELLO WORLD") in R?

<p>hello world (A)</p> Signup and view all the answers

Which function is the most appropriate for merging multiple vectors into a data frame as columns?

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

Which of the following is the correct way to replace all missing values (NA) in a data frame named df with 0?

<p><code>df[is.na(df)] &lt;- 0</code> (B)</p> Signup and view all the answers

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

<p>To apply a function over the rows or columns of a matrix or array. (C)</p> Signup and view all the answers

Which function in R is used to create a contingency table from categorical data?

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

Flashcards

Integer Data Type in R

The data type used for storing whole numbers (integers) in R.

seq() function in R

This function creates a sequence of numbers in R.

length() function in R

Returns the number of elements in a vector.

Vector in R

A data structure in R for storing elements of the same type in a single row or column.

Signup and view all the flashcards

Accessing Matrix Elements

How to access element in a matrix in R

Signup and view all the flashcards

read.csv() function

Used to read a CSV (Comma Separated Values) file into R.

Signup and view all the flashcards

$ operator in R

Accesses elements within a list or data frame by name.

Signup and view all the flashcards

str() function in R

Gives a summarized structure of a data object in R.

Signup and view all the flashcards

%% operator in R

Gives the remainder of a division operation.

Signup and view all the flashcards

install.packages()

Installs packages from repositories like CRAN.

Signup and view all the flashcards

library() function

Loads and attaches a package for current session.

Signup and view all the flashcards

& operator in R

Represents logical AND

Signup and view all the flashcards

TRUE && FALSE

Performs a logical AND operation, returns TRUE/FALSE.

Signup and view all the flashcards

factor() function in R

Used to create a factor variable in R.

Signup and view all the flashcards

tolower() function in R

Converts a string to lowercase.

Signup and view all the flashcards

cbind() function

Combines multiple vectors into a data frame by columns.

Signup and view all the flashcards

Study Notes

  • Integer data types store whole numbers in R.
  • The given R code x <- 5; if(x > 3) { print("Greater than 3") } else { print("Less than or equal to 3") } outputs "Greater than 3"
  • The seq() function creates a sequence of numbers in R.
  • length(c(1, 2, 3, 4, 5)) outputs 5, which is the number of elements in the vector.
  • "table" is not a valid data structure in R.
  • Access the element in the 3rd row and 2nd column of matrix called my_matrix using my_matrix[3, 2].
  • The read.csv() function reads a CSV file in R.
  • The $ operator accesses elements within a list or data frame by name.
  • The str() function gets the structure of a data object in R.
  • 10 %% 3 outputs 1, which is the remainder of 10 divided by 3.
  • The install.packages() function installs packages in R.
  • The library() function loads and attaches a package.
  • & is a logical operator in R.

Studying That Suits You

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

Quiz Team

Related Documents

More Like This

Data Structures and Abstract Data Types Quiz
16 questions
Abstract Data Types and Data Structures
40 questions
Data Types and Structures Quiz
47 questions
Use Quizgecko on...
Browser
Browser