wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

R Programming MCQs

Total questions: 16

Worksheet time: 16mins

Name
Class
Date
1.

Which of the following is a valid way to assign a value to a variable in R?

a)

x := 5

b)

x <- 5

c)

x =: 5

d)

5 == x

2.

Which function is used to get a quick overview of a data frame structure in R?

a)

details()

b)

str()

c)

analyze()

d)

None

3.

What does the select() function do?

a)

Removes rows based on a condition

b)

Modifies values in a column

c)

Selects specific columns from a data frame

d)

Sorts rows

4.

Which function is used to reorder rows based on column values?

a)

filter()

b)

arrange()

c)

group_by()

d)

mutate()

5.

What does summarise(mean_age = mean(age)) return?

a)

The original dataset

b)

A new dataset with one row and the average age

c)

A plot

d)

All ages greater than the mean

6.

What is wrong with this line of code? data %>% filter(age > 30) %>% select[name]

a)

Wrong data type

b)

select uses [] instead of ()

c)

Missing pipe

d)

filter should come after select

7.

What is the output of this code? data %>% filter(gender == 'F') %>% summarise(avg = mean(salary))

a)

All female salaries

b)

One row with average salary of females

c)

Error

d)

A histogram

8.

Which function is used to read a CSV file into R?

a)

read.csv()

b)

load.csv()

c)

open.csv()

d)

write.csv()

9.

How do you write a data frame df to a CSV file named data.csv?

a)

export_csv(df, 'data.csv')

b)

write.csv(df, 'data.csv')

c)

write_csv(df, 'data.csv')

d)

save.csv(df, file = 'data.csv')

10.

Find the error: summarise(data, mean_salary = mean[salary])

a)

Missing data

b)

mean[salary] should be mean(salary)

c)

Wrong function

d)

Brackets are fine

11.

Which of these will cause an error?

a)

filter(data, salary > 50000)

b)

select(data salary)

c)

arrange(data, age)

d)

mutate(data, income = salary * 1.1)

12.

What's wrong with this code? data %>% group_by(department) %>% summarise(avg = average(salary))

a)

group_by cannot be used here

b)

average() should be mean()

c)

Pipe not needed

d)

No error

13.

Which of the following lines contains a syntax error?

a)

df %>% arrange(desc(salary))

b)

df %>% select(name, age)

c)

df %>% filter age > 25

d)

df %>% mutate(bonus = salary * 0.1)

14.

Which of the following is the correct syntax for a for loop in R?

a)

for(i in 1:10) { print(i) }

b)

for i in 1 to 10: print(i)

c)

foreach i in 1:10 { print(i) }

d)

None

15.

Which function is used to loop through each element in a vector in R?

a)

repeat()

b)

apply()

c)

None

d)

for()

16.

What will this code print? x <- 3 if (x > 5) { print('Big') } else { print('Small') }

a)

Big

b)

Nothing

c)

Small

d)

Error