The post is about MCQ on R Language Quiz with Answers. The quiz covers the topics related to R Package qqplot, R Studio, and Data.Frame. Let us start with the MCQs R Language Quiz.
Online Multiple Choice Questions about Learning R Programming. It will help the learners to get knowledge of R not only for learning the language but also to get some practices about Statistics with reference to R Programming.
MCQs R Language Quiz
Which of the following aesthetic attributes can you map to the data in a scatterplot?
What is the role of the x argument in the following code? ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut))
Which of the following are the benefits of adding labels and annotations to your plot?
What function can you use to put a text label inside the grid of your plot to call out specific data points?
Which of the following are operations you can perform in ggplot2?
When creating a plot in ggplot you must set the mapping argument of a function. Which function has the mapping argument?
Which ggplot function is used to define the mappings of variables to visual representations of data?
Which of the following are the benefits of using ggplot2?
What argument of the labs() function can a data analyst use to add text outside of the grid area of a plot?
Which statement about the ggsave() function is correct?
A data analyst is working with the penguin’s data. The analyst creates a scatterplot with the following code: ggplot(data = penguins) + geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, alpha = species))
What does the alpha aesthetic do to the appearance of the points in the plot?
The ___________ creates a scatterplot and then adds a small amount of random noise to each point in the plot to make the points easier to find.
In R studio, what default options does the Export functionality of the Plots tab give for exporting plots?
Which of the following are operations you can perform in ggplot2?
In ggplot2, you use the plus sign (+) to add a layer to your plot.
Which of the following is NOT a valid data structure in R?
What is the purpose of the rep() function in R?
Which package is associated with data visualization in R?
What does the data.frame function do in R?
Data frames can be converted to a matrix by calling data.
The post is about the R Language Reference Guide subsetting Vectors, Lists, Matrices, and Data Frames in R Language.
R language Reference Guide is about learning R Programming with a short description of the widely used commands. It will help the learner and intermediate user of the R Programming Language to get help with different functions quickly. This R language reference is classified into different groups. Let us start with the R Language Reference Guide – III.
Table of Contents
This R Language Quick Reference contains R commands about subsetting in R, such as subsetting of vectors, matrices, lists, data frames, arrays, and factors. It also discusses setting the different properties related to R language data types.
Subsetting Vectors: Quick R Language Reference
The following are ways to subset or slice the values from a vector.
R Command
Short Description
x[1:5]
Select elements of $x$ by index
x[-(1:5)]
Exclude elements of $x$ by index
x[c(TRUE, FALSE)]
Select elements of $x$ corresponding to the True value
x[c(“a”, “b”)]
Select elements of $x$ by name
Subsetting Lists in R Language
The following methods are used to subset or slice a list in R Language.
R Command
Short Description
x[1:5]
Extracts a sublist of the list $x$
x[-(1:5)]
Extract a sublist by excluding elements of list $x$
x[c(TRUE, FALSE)]
Extract a sublist with logical subscripts
x[c(“a”, “b”)]
Extract a sublist by name
x[[2]]
Extract an element of the list $x$
x[[“a”]]
Extract the element with the name “a” from list $x$
x$a
Extract the element with the name “a” from list $x$
Subsetting Matrices in R: A Quick Reference
To subset or extract certain elements from a matrix follow the ways described below.
R Command
Short Description
x[i, j]
Extracts elements of matrix $x$, specified by row $i$ and column $j$
x[i, j] = v
Set or rest the elements of matrix $x$, specified by row $i$ and column $j$
x[i, ]
Extracts $i$th row of a matrix $x$
x[i, ] = v
Set or resets the $i$th row of a matrix $x$ specified by $i$th row
x[ , j]
Extracts the $j$ column of a matrix $x$
x[ , j] = v
Sets or resets the $j$ column of matrix $x$
x[i]
Subets a matrix $x$ as a vector
x[i] = v
Sets or resets the $i$th elements (treated as a vector operation)
The article is about the R Language Quick Reference Guide. This Quick Reference will help you to learn about creating vectors, matrices, data frames, lists, and factors. You will also learn about setting properties of different data types in R Language.
Table of Contents
R Language Quick Reference Guide
R language Quick Reference Guide is about learning R Programming with a short description of the widely used commands. It will help the learner and intermediate user of the R Programming Language to get help with different functions quickly. This Quick Reference is classified into different groups. Let us start with R Language Quick Reference Guide – II.
This R Language Quick Reference Guide contains R commands about creating vectors, matrices, lists, data frames, arrays, and factors. It also discusses setting the different properties related to R language data types.
Creating Vectors in R Language
The creation of a row or column vector in the R Language is very important. One can easily create a vector of numbers, characters/ strings, complex numbers, and logical values, and can concatenate the elements. The following are different commands for creating Vectors in R
R command
Short Description
c(a1, a2, …, an)
Concatenates all $n$ elements to a vector
logical(n)
Creates a logical vector of length $n$ (containing false)
numeric(n)
Creates a numeric vector of length $n$ (containing zeros)
character(n)
Creates a character vector of length $n$ (containing an empty string)
complex(n)
Creates a complex vector of length $n$ (containing zeros)
Creating Lists in R Language
Creating Lists in R is important as it can store different types of data and even lists. A vector can also be used to create a list of $k$ elements. The following are ways for creating lists in R language.
R Command
Short Description
list(e1, e2, … ek)
Combines all $k$ elements as a list
vector(k, “list”)
Creates a list of length $k$ (the elements are all NULL)
Creating Matrices in R Language
Two-dimensional data can be created using the matrix command in R.
R Command
Short Description
matrix(x, nr = r, nc = c)
Creates a matrix from $x$ (column as major order)
matrix(x, nr = r, nc = c)
Creates a matrix from $x$ (row as major order)
Creating Factors in R Language
To create categorical variables, R has a concept of factors as variables. All factors have levels that may have ordered factors.
R Command
Short Description
factor(x)
Creates a factor from the values of variable $x$
factor(x, levels = 1)
Creates a factor with the given level set from the values of the variable $x$
ordered(x)
Creates an ordered factor with the given level set from the values of the variable $x$
levels(x)
Gives the levels of a factor or ordered factor
levels(x) = v
Set or reset the levels of a factor or ordered factor
Creating a Data Frame in R Language
A data frame is a tabular data format used for statistical data analysis. The format of the data is like data entered in spreadsheets for data analysis.
R Command
Short Description
data.frame(n1=x1, n2=x2, ….)
Creates a data frame
R Language Data Type Properties
Every data object has different properties. These properties can be used to find out the number of rows in a vector or matrix, the number of columns, names of rows and columns of a matrix or data frame.
R Command
Short Description
length(x)
Gives the number of elements in a variable $x$
mode(x)
Tells about the data type of the variable $x$
nrow(x)
Displays the number of rows of a vector, array, or data frame $x$
ncol(x)
Displays the number of columns (variable) of a vector, array, or data frame $x$
dim(x)
Displays the dimension (number of rows and columns) of a matrix, data frame, array, or list $x$
row(x)
Matrix of row indices for matrix-like object $x$
col(x)
Matrix of column indices for matrix-like object $x$
rownames(x)
Get the row names of the matrix-like object $x$
rownames(x)=v
Set the row names of the matrix-like object $x$ to $v$
colnames(x)
Get the column names of the matrix-like object $x$
colnames(x)=v
Set the column names of the matrix-like object $x$ to $v$
dimnames(x)
Get both the row and column names (in a matrix, data frame, or list)
dimnames(x)=list(rn, cn)
Set both the row and column names
names(x)
Gives the names of $x$
namex(x)=v
Sets or resets the names of $x$ to $v$
names(x)=NULL
removes the names from $x$
row.names(df)
Gives the observation names from a data frame
row.names(df)=v
Sets or resets the observation names of a data frame