n to all three vectors to see what would happen. If the function requires more than one input x, then you just create other objects as needed. sum (x) sum of the elements of x prod (x) product of the elements of x max (x) maximum of the elements of x min(x) minimum of
Play and practice all the functions that we listed here.
What I would like you to do is to first create three
x1 = c( TRUE, FALSE, TRUE)
x2 = c( 0, -2.5, 1, 3, 5.9 )
x3 = c( "a1", "a2", "za", "zz", "0", "1")
and apply each function to all three vectors to see what would happen. If the function requires more than one input x, then you just create other objects as needed.
sum (x) |
sum of the elements of x |
prod (x) |
product of the elements of x |
max (x) |
maximum of the elements of x |
min(x) |
minimum of the elements of x |
which. max (x) |
returns the index of the greatest element of x |
which. min(x) |
returns the index of the smallest element of x |
range (x) |
id. than c (min(x), max (x)) |
length (x) |
number of elements in x |
mean (x) |
mean of the elements of x |
median (x) |
median of the elements of x |
round (x, n) |
rounds the elements of x to n decimals |
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)) |
rank (x) |
ranks of the elements of x |
10g(x, base) |
computes the logarithm of x with base base |
scale (x) |
if x is a matrix, centers and reduces the data; to center only use the option center=FALSE, to reduce only scale=FALSE (by default center=TRUE, scale=TRUE) |
pmin(x,y,.. |
a vector which ith element is the minimum of x [1], y [il, ... |
pmax (x,y,.. |
id. for the maximum |
cumsum (x) |
a vector which ith element is the sum from x [1] to x [i] |
cumprod (x) |
id. for the product |
cummin (x) |
id. for the minimum |
cummax (x) |
id. for the maximum |
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 operation 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 logical) |
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) (suppresses 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) |
table (x, y) |
contingency table of x and y |
subset (x, ...) |
returns a selection of x with respect to criteria (..., typically com-parisons: x$V1 < 10); if x is a data frame, the option select gives the variables to be kept (or dropped using a minus sign) |
samplex, size) |
resample randomly and without replacement size elements in the vector x, the option replace = TRUE allows to resample with replace- |
Step by step
Solved in 3 steps with 1 images