Data selection and manipulation Flashcards Preview

R > Data selection and manipulation > Flashcards

Flashcards in Data selection and manipulation Deck (16)
Loading flashcards...
1

which.max(x)

returns the index of the greatest element of x

2

which.min(x)

returns the index of the smallest element of x

3

rev(x)

reverses the elements of x

4

sort(x)

sorts the elements of x in increasing order; to sort in decreasing
order: rev(sort(x))

5

cut(x,breaks)

divides x into intervals (factors); breaks is the number
of cut intervals or a vector of cut points

6

match(x, y)

returns a vector of the same length than x with the elements
of x which are in y (NA otherwise)

7

which(x == a)

returns a vector of the indices of x if the comparison op-
eration is true (TRUE), in this example the values of i for which x[i] == a (the argument of this function must be a variable of mode logi- cal)

8

choose(n, k)

computes the combinations of k events among n repetitions = n!/[(n − k)!k!]

9

na.omit(x)

suppresses the observations with missing data (NA) (sup- presses the corresponding line if x is a matrix or a data frame)

10

na.fail(x)

returns an error message if x contains at least one NA

11

unique(x)

if x is a vector or a data frame, returns a similar object but with the duplicate elements suppressed

12

table(x)

returns a table with the numbers of the differents values of x (typically for integers or factors)

13

subset(x, ...)

returns a selection of x with respect to criteria (..., typically comparisons: x$V1 < 10); if x is a data frame, the option select gives the variables to be kept or dropped using a minus sign

14

sample(x, size)

resample randomly and without replacement size ele- ments in the vector x, the option replace = TRUE allows to resample with replacement

15

prop.table(x,margin=)

table entries as fraction of marginal table

16

with(data, expr, ...)

Evaluate an R expression in an environment constructed from data, possibly modifying the original data.