This shows you the differences between two versions of the page.
math121b:r [2020/04/20 08:36] pzhou created |
math121b:r [2020/04/20 09:52] (current) pzhou [Cheat Sheat] |
||
---|---|---|---|
Line 5: | Line 5: | ||
reference: {{ : | reference: {{ : | ||
- | assignment | ||
- | a <- 10 | ||
- | create a vector | ||
- | a = c(2,3,8,0) | ||
- | | Function | + | === variable manipulations === |
- | | mean(x) |Mean of the numbers in vector | + | | function |
- | | median(x) |Median of the numbers in vector | + | | c(1,3,4,5) | create a vector | |
- | | var(x) |Estimated variance of the population | + | | 2:5 | create a sequence |
- | | sd(x) | standard deviation, square | + | | y[3] | say y is a vector, take the 3rd entry out of y | |
+ | | seq(2,10, by=0.5) | create a sequence, start from 2, ending at 10, step size = 0.5 | | ||
+ | | rep(1:3, times = 2) | repeat | ||
+ | | rep(1:3, each = 2) | repeat the sequence (1,2,3), each entry 2 times, so get (1, | ||
+ | |||
+ | === if .. else .. === | ||
+ | < | ||
+ | if (i > 3) | ||
+ | { | ||
+ | print(‘Yes’) | ||
+ | } else { | ||
+ | print(‘No’) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === For loop === | ||
+ | < | ||
+ | for (i in 1:4) | ||
+ | { | ||
+ | j <- i + 10 | ||
+ | print(j) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === function === | ||
+ | < | ||
+ | square | ||
+ | { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Sampling ==== | ||
+ | |||
+ | |Distribution | sampling | density function | cumulative density function | | ||
+ | | Normal | rnorm | dnorm | pnorm | | ||
+ | | Poisson | rpois | dpois | ppois | | ||
- |