Join Now
Home Aptitude Reasoning DI VA GK CA CA Hindi Quiz Placements
What is the output of the following R code snippet?
x <- 1:10y <- x[x %% 2 == 0]print(y)
1 3 5 7 9
2 4 6 8 10
1 2 3 4 5
2 3 5 7 11
x <- 1for (i in 1:5) { x <- x * i}print(x)
5
24
120
720
x <- 2y <- 3z <- x + yprint(z)
2
3
Error
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)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.
x <- c(1, 2, 3, 4, 5)y <- sum(x)print(y)
1
15
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)library(ggplot2)ggplot(z, aes(x = y, y = x)) + geom_bar(stat = "identity")
A bar chart with bars at the y-axis labels "one", "two", "three", "four", and "five", with heights corresponding to the x values in the z data frame.
A bar chart with bars at the x-axis labels "one", "two", "three", "four", and "five", with heights corresponding to the y values in the z data frame.
An error message, because ggplot2 cannot be used with non-numeric data.
An error message, because the geom_bar function cannot be used with non-numeric data.
x <- "Hello"y <- "World"z <- paste(x, y)print(z)
HelloWorld
Hello World
NA
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, y)) + geom_point()
A scatterplot of x vs y.
A line plot of x vs y.
A bar plot of x vs y.