Multiple Choices: Data Frames

Questions

  1. What function is used to create a data frame in R?
  1. If df <- data.frame(A = 1:3, B = c("X", "Y", "Z")), what does df$B return?
  1. What is the output of nrow(data.frame(x = 1:4, y = 5:8))?
  1. Given df <- data.frame(Name = c("Alice", "Bob"), Age = c(25, 30)), how would you select the first row of the data frame?
  1. If df <- data.frame(A = 1:5, B = c(NA, 2, NA, 4, 5)), what will na.omit(df) do?
  1. If df <- data.frame(x = 1:5, y = c(10, 20, 30, 40, 50)), what does df[ , "y"] return?
  1. What does str(df) display for a data frame df?
  1. Given df <- data.frame(A = c(5, 3, 2, 8), B = c("A", "B", "C", "D")), what will df[order(df$A), ] return?
  1. Which of the following will add a new column C with values c(100, 200, 300, 400) to df <- data.frame(A = 1:4, B = 5:8)?
  1. If df <- data.frame(Name = c("Alice", "Bob", "Carol"), Age = c(25, NA, 30)), what does is.na(df$Age) return?
  1. Which function would you use to view the first few rows of a data frame df? ::: {.cell}
  1. Given df <- data.frame(A = c(2, 4, 6), B = c("X", "Y", "Z")), what will df[1:2, ] return? ::: {.cell}

:::

  1. If df <- data.frame(A = 1:3, B = 4:6), which command will rename the columns to X and Y? ::: {.cell}

:::

  1. Which function gives a summary of each column in a data frame df, including min, max, mean, and quartiles? ::: {.cell}

:::

  1. What does ncol(df) return for a data frame df? ::: {.cell}

:::

  1. Given df1 <- data.frame(A = 1:3, B = 4:6) and df2 <- data.frame(A = 7:9, B = 10:12), what does rbind(df1, df2) do? ::: {.cell}

:::

  1. How would you select only the columns B and C from a data frame df? ::: {.cell}

:::

  1. If df <- data.frame(A = 1:5, B = 6:10), which of the following commands will add a new row c(11, 12) to df? ::: {.cell}

:::

  1. Which function checks if an object df is a data frame? ::: {.cell}

:::

  1. If df <- data.frame(A = c("apple", "banana", "apple"), B = c(5, 3, 8)), which command will count the number of occurrences of each unique value in column A? ::: {.cell}

:::

  1. Given df <- data.frame(A = c(3, 1, 2), B = c(9, 6, 4)), what does df[order(df$A), ] return? ::: {.cell}

:::

  1. If df <- data.frame(X = c(1, NA, 3, 4), Y = c("A", "B", NA, "D")), which function would return a logical vector indicating missing values in X? ::: {.cell}

:::

  1. Which function can you use to combine two data frames df1 and df2 with the same columns, adding df2 as rows to df1? ::: {.cell}

:::

  1. If df <- data.frame(A = 1:5, B = letters[1:5]), what will df[ , 1] return? ::: {.cell}

:::

  1. Given df <- data.frame(A = c(1, 2, 3, 4), B = c(10, 20, 30, 40)), which command will select rows where column B is greater than 20? ::: {.cell}

:::

  1. Which function will display the names of columns in a data frame df? ::: {.cell}

:::

  1. If df <- data.frame(A = 1:5, B = 6:10), what does df[-1, ] return? ::: {.cell}

:::

  1. To find the unique values in a column A of a data frame df, which command would you use? ::: {.cell}

:::

  1. If df <- data.frame(A = 1:3, B = 4:6), what does dim(df) return? ::: {.cell}

:::

  1. Given df <- data.frame(A = c(1, 2, 3), B = c("X", "Y", "Z")), how would you convert column A to a character type? ::: {.cell}

:::

:::