Data selection and manipulation Flashcards
which.max(x)
returns the index of the greatest element of x
which.min(x)
returns the index of the smallest element of x
rev(x)
reverses the elements of x
sort(x)
sorts the elements of x in increasing order; to sort in decreasing
order: rev(sort(x))
cut(x,breaks)
divides x into intervals (factors); breaks is the number
of cut intervals or a vector of cut points
match(x, y)
returns a vector of the same length than x with the elements
of x which are in y (NA otherwise)
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)
choose(n, k)
computes the combinations of k events among n repetitions = n!/[(n − k)!k!]
na.omit(x)
suppresses the observations with missing data (NA) (sup- presses the corresponding line if x is a matrix or a data frame)
na.fail(x)
returns an error message if x contains at least one NA
unique(x)
if x is a vector or a data frame, returns a similar object but with the duplicate elements suppressed
table(x)
returns a table with the numbers of the differents values of x (typically for integers or factors)
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
sample(x, size)
resample randomly and without replacement size ele- ments in the vector x, the option replace = TRUE allows to resample with replacement
prop.table(x,margin=)
table entries as fraction of marginal table