Join Now
Home Aptitude Reasoning DI VA GK CA CA Hindi Quiz Placements
What is the output of the following R code snippet?
x <- c(1, 2, 3, 4, 5)y <- c("one", "two", "three", "four", "five")z <- data.frame(x, y)summary(z)
A summary of the x and y vectors, including the mean, median, and quartiles of x.
A summary of the x and y vectors, including the number of missing values in each column.
A summary of the z data frame, including the number of observations, the mean, median, and quartiles of x, and the counts and percentages of each unique value of y.
Error
x <- c(1, 2, 3, 4, 5)y <- c("one", "two", "three", "four", "five")z <- data.frame(x, y)library(dplyr)group_by(z, y) %>%summarize(mean_x = mean(x), sd_x = sd(x))
A data frame with three columns: y, mean_x, and sd_x, containing the unique values of y in the z data frame, along with the mean and standard deviation of the x values for each value of y.
A data frame with two columns: mean_x and sd_x, containing the mean and standard deviation of the x values in the z data frame, grouped by the y values.
An error message, because the group_by function can only be used on numeric columns.
An error message, because the summarize function cannot be used on grouped data.
x <- c(1, 2, 3, 4, 5)y <- sum(x)print(y)
1
5
15
x <- c(1, 2, 3, 4, 5)y <- c("one", "two", "three", "four", "five")z <- data.frame(x, y)library(dplyr)summarize(z, mean_x = mean(x), sd_x = sd(x))
A data frame with two columns: mean_x and sd_x, containing the mean and standard deviation of the x values in the z data frame.
A data frame with three columns: x, y, and mean_x, containing the original x and y columns, and a new column mean_x with the mean of the x values.
An error message, because the summarize function can only be used on grouped data.
An error message, because the mean and sd functions cannot be used on character columns.
x <- c(1, 2, 3, 4, 5)y <- c(2, 3, 4)z <- x[!x %in% y]print(z)
1 2 3
1 5
2 3 4
4 5
x <- c(1, 2, 3, 4, 5)y <- c("one", "two", "three", "four", "five")z <- data.frame(x, y)library(ggplot2)ggplot(z, aes(x = x, y = y)) + geom_point()
A scatterplot with points at the (x, y) coordinates of the data in the z data frame.
A scatterplot with points at the (y, x) coordinates of the data in the z data frame.
An error message, because ggplot2 cannot be used with data frames.
An error message, because geom_point() cannot be used with non-numeric data.
x <- c(1, 2, 3, 4, 5)y <- c("one", "two", "three", "four", "five")z <- data.frame(x, y)library(dplyr)mutate(z, x_squared = x^2)
A data frame with three columns: x, y, and x_squared, containing the original x and y columns, and a new column x_squared with the squares of the x values.
A data frame with two columns: x and y, containing the original x and y columns, and no new columns.
An error message, because the mutate function can only be used on numeric columns.
An error message, because the ^ operator cannot be used on vectors.
x <- c(1, 2, 3, 4, 5)y <- c("one", "two", "three", "four", "five")z <- data.frame(x, y)subset(z, x %% 2 == 0)
A data frame with two columns: x and y, with the rows where x is even.
A data frame with two columns: x and y, with the rows where y is even.
A data frame with two columns: x and y, with the rows where both x and y are even.
x <- c(1, 2, 3, 4, 5)y <- c("one", "two", "three", "four", "five")z <- data.frame(x, y)library(dplyr)filter(z, x > 3)
A data frame with two columns: x and y, containing the rows where x is greater than 3.
A data frame with two columns: x and y, containing the rows where y is greater than 3.
A data frame with two columns: x and y, containing the rows where x and y are greater than 3.
x <- c(1, 2, 3, 4, 5)y <- c("one", "two", "three", "four", "five")z <- data.frame(x, y)z$y <- as.factor(z$y)levels(z$y)
1 "2" "3" "4" "5"
one "two" "three" "four" "five"
five "four" "one" "three" "two"