What is a data frame in R?

  • A graphical representation of data
  • A collection of data elements of the same data type
  • A two-dimensional table-like data structure
  • A statistical model used for forecasting
A data frame in R is a two-dimensional table-like data structure where columns can contain different data types. It is similar to a spreadsheet or a database table, where each column represents a variable and each row represents an observation.

In R, the ________ function can be used to check if a value is numeric.

  • is.character()
  • is.factor()
  • is.logical()
  • is.numeric()
The is.numeric() function in R is used to check if a value is numeric. It returns TRUE if the value is numeric and FALSE otherwise.

What would be the output if you try to print a variable that doesn't exist in R?

  • A blank output
  • An error message
  • The string "NA"
  • The string "NULL"
If you try to print a variable that doesn't exist in R, you will get an error message stating "Error: object 'x' not found", where 'x' is the name of the non-existent variable. This is because R tries to find the variable in the environment and fails when it does not exist.

In R, the ________ function is used to calculate the natural logarithm of a number.

  • ln()
  • log()
  • log10()
  • natural_log()
The log() function in R is used to calculate the natural logarithm of a number. By default, it computes natural logarithms, but you can also provide a base as the second argument. For example, log(7) would return the natural logarithm of 7.

In R, to access the first element of an array named myarray, you would use ______.

  • myarray[1]
  • myarray[[1]]
  • myarray[1, 1]
  • myarray[[1, 1]]
In R, to access the first element of an array named myarray, you would use myarray[1]. The square brackets [] are used to extract elements from an array. The index 1 refers to the first element of the array.

Suppose you're asked to create a pie chart in R that shows the distribution of a categorical variable in a data set. How would you do it?

  • Use the pie() function and provide a vector of non-negative numeric values representing the proportions of the segments
  • Use the barplot() function and specify the categorical variable as the x argument
  • Use the plot() function with type = "pie" and specify the categorical variable as the data argument
  • Use the ggplot2 package and the geom_bar() function with the categorical variable as the x aesthetic
To create a pie chart in R that shows the distribution of a categorical variable in a data set, you would use the pie() function. Provide a vector of non-negative numeric values representing the proportions of the segments corresponding to each category.

If you want to include a literal backtick in a string in R, you would use the escape sequence ________.

  • `
  • t
  • b
  • '
In R, to include a literal backtick in a string, you would use the escape sequence ' . For example, "This is a backtick: '" would result in the string This is a backtick: `.

The ______ function in R can be used to find the index of the maximum value in a vector.

  • which.max()
  • which.min()
  • index.max()
  • index.min()
The which.max() function in R can be used to find the index of the maximum value in a vector. The which.max() function returns the index of the first occurrence of the maximum value.

The ______ function in R returns the mode of an object, which is its data type.

  • mode()
  • typeof()
  • class()
  • str()
The typeof() function in R returns the mode of an object, which represents its data type. It is used to determine the data type of the object.

What are the rules for naming variables in R?

  • Can start with a number, Can contain special characters, Case-insensitive
  • Can start with a number, Cannot contain special characters, Case-insensitive
  • Cannot start with a number, Can contain special characters, Case-sensitive
  • Cannot start with a number, Cannot contain special characters, Case-sensitive
Variables in R should start with a letter, and can contain letters, numbers, period (.) and underscore (_). Variable names in R are also case sensitive, so "mydata" and "MyData" would refer to different variables.