Home
21.
What is the length of this list?
list(alpha = 1, list(beta = 2, gamma = 3, delta = 4), eta = NULL)
## $alpha
## [1] 1
##
## [[2]]
## [[2]]$beta
## [1] 2
##
## [[2]]$gamma
## [1] 3
##
## [[2]]$delta
## [1] 4
##
##
## $eta
## NULL

3. The inner list counts as one element, and so does the NULL element.

22.
Where might you find a pairlist being used?

When passing arguments to functions, when calling formals, or in the global environment variable .Options.

23.
Name as many ways as you can think of to create a subset of a data frame.

You can use matrix-style indexing with pairs of positive integers/negative integers/ logical values/characters in single square brackets. You can also use list-style indexing with one index value inside single or double square brackets, or the dollar sign ($) operator. Thirdly, you can call the subset function.

24.
How would you create a data frame where the column names weren’t unique, valid variable names?

By passing check.names = FALSE to data.frame.

25.
Which function would you use to append one data frame to another?

rbind for appending vertically or cbind for appending horizontally.

26.
What is another name for the global environment?

The user workspace.

27.
How would you convert a list to an environment?

list2env is the best solution, but as.environment also works.

28.
How do you print the contents of a function to the console?

Just type its name.

29.
Name three functions that tell you the names of the formal arguments of a function.

formals, args, and formalArgs.

30.
What does the do.call function do?

do.call calls a function with its arguments in a list form.