R Variables Vectors and Random Numbers Flashcards (38 cards)

All cards

1Question

What are R's primary data types?

Answer

Numeric, integer, character, logical, and complex.

2Question

How does R represent numbers by default, and what marks an integer explicitly?

Answer

Numbers default to double-precision numeric values; the L suffix marks an integer, as in 42L.

3Question

What may begin an R variable name?

Answer

A letter or a dot not immediately followed by a number.

4Question

Which characters may appear later in an R variable name?

Answer

Letters, numbers, dots, or underscores.

5Question

What characters are prohibited in R variable names?

Answer

Spaces and special characters.

6Question

Which kinds of words should not be used as R variable names?

Answer

Reserved words such as if, else, TRUE, FALSE, NULL, for, or function.

7Question

Which R data structures hold elements of the same type?

Answer

Vectors and matrices.

8Question

What is a vector?

Answer

An ordered collection of elements of the same type.

9Question

What values does `c(2, 6, 1, 3, 11)` create?

Answer

2, 6, 1, 3, and 11.

10Question

What is a factor in R?

Answer

A vector representing a categorical variable whose labels have underlying numeric codes.

11Question

What is an ordered factor?

Answer

A categorical factor whose levels have a specified order.

12Question

Which prefixes identify R density, cumulative probability, quantile, and random-generation functions?

Answer

The prefixes are dxxx, pxxx, qxxx, and rxxx, respectively.

13Question

What does `set.seed(number)` set for subsequent pseudo-random generation?

Answer

The random seed.

14Question

How are character values represented in R?

Answer

As text enclosed in single or double quotes.

15Question

Which case-sensitive values represent logical data in R?

Answer

TRUE and FALSE.

16Question

What parts do complex values contain in R?

Answer

Real and imaginary parts.

17Question

Which symbol denotes the imaginary part in R complex values?

Answer

The symbol i, as in 3 + 4i.

18Question

What do R's is.xxxx functions do?

Answer

They check a data type.

19Question

What do R's as.xxxx functions do?

Answer

They transform a value's type.

20Question

How does R treat variable names that differ only in capitalization?

Answer

As different names.

21Question

Which listed name is a valid R variable name: myVariable, data.frame, .hiddenVar, or var_123?

Answer

All four are valid R variable names.

22Question

Which listed names are invalid R variable names: 1stVar, my-var, or NULL?

Answer

All three are invalid R variable names.

23Question

What does the R function `t()` do to a vector or matrix?

Answer

It transposes it.

24Question

How does `t(v)` display `v <- c(2, 6, 1, 3, 11)`?

Answer

As a row.

25Question

What values does `seq(from=-4, to=5, by=1.5)` generate?

Answer

-4.0, -2.5, -1.0, 0.5, 2.0, 3.5, and 5.0.

26Question

What step size does `seq(from=-4, to=5)` use when `by` is omitted?

Answer

1.

27Question

What does `rep(2, 5)` return?

Answer

The value 2 repeated five times.

28Question

What does R's factor() function do to a character vector of categories?

Answer

It converts the vector into a factor with category levels.

29Question

What levels does factor(gender) have for the given male-and-female gender vector?

Answer

Female and male.

30Question

What order does ordered(edu, levels=c("h", "u", "p")) assign?

Answer

h<u<ph < u < p

31Question

Which distribution families are included in the R handout?

Answer

Beta, binomial (including Bernoulli), Cauchy, chi-squared, exponential, F, gamma, geometric, hypergeometric, log-normal, multinomial, negative binomial, normal, Poisson, Student's t, uniform, and Weibull.

32Question

What does `rnorm(1)` generate by default?

Answer

One random value from the standard normal distribution.

33Question

What does `rnorm(n=31, mean=14, sd=2)` generate?

Answer

31 random values from a normal distribution with mean 14 and standard deviation 2.

34Question

What does `round(runif(1, min=1, max=6), 0)` produce?

Answer

A random integer obtained by rounding a uniform value between 1 and 6.

35Question

What can the random package generate?

Answer

Integers, random sequences, and random strings.

36Question

What values does `seq(4, 5, length.out=5)` generate?

Answer

4.00, 4.25, 4.50, 4.75, and 5.00.

37Question

What labels can the labels argument assign to ordered levels h, u, and p, respectively?

Answer

High school, undergraduate, and postgraduate.

38Question

What must be supplied to an R distribution function?

Answer

Parameters appropriate to that distribution.

Test yourself with the quiz

Answer 11 questions on R Variables Vectors and Random Numbers.

1. In R, what type is assigned to each value in `a <- 42` and `b <- 42L`, respectively?

2. Which set lists R’s five primary data types?

Take the quiz →

Read the study guide

Go over the full study guide for R Variables Vectors and Random Numbers.

Read the study guide →

Related classes

Make your own flashcards

Upload your class notes and Revizly writes your flashcards in about a minute.

Flashcard maker