R Language Learning - Basic Operations & create random numbers

R is based on a vector (vector) operation

1, to create a vector: named V
V C = (1,4,4,3,2,2,3)
2, returns the value of the second vector V to 4:
V [C (2,3,4) ]
v [2:. 4]
Here Insert Picture Description
3, returns to the second sequence vectors, the first four and three values: v [C (2,4,3)]
Here Insert Picture Description. 4, the vector v return value is less than 3: v [ v <. 3]
Here Insert Picture Description. 5, v deleting the second element, and then return: v [-2]
note
after this time however any vector V elements 7, the command returns v R only requires removing the second element: Note value of
6, to delete the first two to four elements, then return: v [-2: -4]
Here Insert Picture Description
. 7, the query element is less than 3 v: v [v <3]
Here Insert Picture Description
. 8, v query which all elements equal to 3 : which (v == 3)
Here Insert Picture Description
return the result is a vector v in the fourth and seventh elements equal to 3
CAUTION: R language, two equal sign test are equal, an equal sign for the assignment

9, the maximum value and the minimum value of v query: which.max (v), which.min (v)
Here Insert Picture Description
10, creates a random number:
Here Insert Picture Description
Note: If a separate function runif create random number () after each execution, data The results are not the same, as in FIG. If then preceded by a set.seed (), will ensure consistent test data, as shown below. set.seed () function can only be used once.
Here Insert Picture Description
runif (): random number created from the uniform distribution;
rnorm (): random number created from a normal distribution;
rexp (): random number created from the exponential distribution;
rbinom (): creates a random number from the binomial distribution;
rnbinom (): random number created from the negative binomial distribution;
rgeom (): random number created from the geometric distribution;

11, the decimal rounding: floor () is rounded down; ceiling () is rounded up; round (a, n) is the n-bit decimal a decimal places
Here Insert Picture Description

Published an original article · won praise 0 · Views 14

Guess you like

Origin blog.csdn.net/alyssa_yu/article/details/104599038