User Tools

Site Tools


math121b:r

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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: {{ :math121b:r-cheat-sheet-3.pdf | CheatSheat PDF}} reference: {{ :math121b:r-cheat-sheet-3.pdf | CheatSheat PDF}}
  
-assignment 
-    a <- 10 
-create a vector 
-    a = c(2,3,8,0) 
  
-Function |What it Calculates +=== variable manipulations === 
-mean(x |Mean of the numbers in vector x. +function meaning |  
-median(x) |Median of the numbers in vector +c(1,3,4,5) | create a vector | 
-var(x) |Estimated variance of the population from which the numbers in vector x are sampled +2:5 | create a sequence (2,3,4,5)| 
-sd(x) | standard deviation, square root of var(x) |+| 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 the sequence (1,2,3), 2 times, so get (1,2,3,1,2,3) |  
 +rep(1:3, each = 2) | repeat the sequence (1,2,3), each entry 2 times, so get (1,1,2,2,3,3) |  
 + 
 +=== if .. else .. === 
 +<code> 
 +if (i > 3) 
 +{  
 +  print(‘Yes’) 
 +} else {  
 +  print(‘No’) 
 +
 +</code> 
 + 
 +=== For loop === 
 +<code> 
 +for (i in 1:4) 
 +{  
 +  j <- i + 10 
 +  print(j)  
 +
 +</code> 
 + 
 +=== function === 
 +<code> 
 +square <- function(x) 
 +
 +   squared <- x*x 
 +   return(squared) 
 +
 +</code> 
 + 
 + 
 +==== Sampling ==== 
 + 
 +|Distribution | sampling | density function | cumulative density function | 
 +| Normal | rnorm | dnorm | pnorm | 
 +| Poisson | rpois | dpois | ppois | 
  
-  
math121b/r.1587396989.txt.gz · Last modified: 2020/04/20 08:36 by pzhou