Skip to content

Commit

Permalink
vault backup: 2023-09-12 21:36:16
Browse files Browse the repository at this point in the history
Affected files:
content/notes/university/year3/cs3002/cs3002-lab1.md
  • Loading branch information
pietraferreira committed Sep 12, 2023
1 parent 3e16170 commit 678c4fd
Showing 1 changed file with 62 additions and 4 deletions.
66 changes: 62 additions & 4 deletions content/notes/university/year3/cs3002/cs3002-lab1.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ year: '3'
---
The lab sheet can be found [here](assets/university/year3/R_IntroLab_v3.pdf).

## Notes
# Notes
---
- R is **case-sensitive**, so `view` doesn't work but `View` does.
- To create scatterplots:
- Column name:
Expand All @@ -35,14 +36,71 @@ The lab sheet can be found [here](assets/university/year3/R_IntroLab_v3.pdf).
lmfire=line(mydata$ISI~mydata$temp)
abline(coef(lmfire))
```


## R Cheatsheets
## A (very) short introduction to R
---
R is for statistical computing and graphics, and iti s a public domain (GNU) project.

To set the working directory: `setwd("/Users/pietra/etc")`.

To check the installed packages: `library()` in the console.
- To install: `install.packages("geometry")`.
- We then load: `library("geometry")`.

To remove all variables from memory: `rm(list=ls())`.

To define a vector we use **c** meaning **concatenate**: `b=c(3,4,5)`.

- `rnorm()`: creates random samples from a normal distribution.
- `rnorm(10, mean=1.2, sd=3.4)`.

We can then do something like:

```r
x = rnorm(100)
plot(x)
```

In doubt, we can do `help(rnorm)` or even `example(rnorm)`.

- `CTRL+SHIFT+S` runs the whole script, whereas `CTRL+ENTER` runs a line.

### Vectors
**WE INDEX FROM 1, NOT 0!!!**

- To construct: `vec1 = c(1,4,5,8,10)`.
- Alternatively: `vec1 = seq(from=0, to=1, by=0.25)`.
- To change a value: `vec1[3] = 12`.
- We can then do things like: `sum(vec1)`.

### Matrices
2-d vectors.

- To construct: `mat=matrix(data=c(9,2,3,4,5,6),ncol=3)`.
- Can also specify `nrow`.
- We get:

| | \[,1\] | \[,2\] | \[,3\] |
| ------ | ------ | ------ | ------ |
| \[1,\] | 9 | 3 | 5 |
| \[2,\] | 2 | 4 | 6 |

Some operations are:
- Address an element: `mat[1,2]`.
- Select a whole row: `mat[2,]`.
- Function example: `mean(mat)`.

# R Cheatsheets
- [Graph Parameters CheatSheet](assets/university/year3/R_Graph_Parameters_CheatSheet.pdf).
- [Base R CheatSheet](assets/university/year3/Base_R_CheatSheet.pdf).
- [Data Transformation CheatSheet](assets/university/year3/R_Data_Transformation_CheatSheet.pdf).

## Commands
- Full manual [here](http://cran.r-project.org/doc/manuals/%20R-intro.pdf).
- Short [reference card](http://zoonek2.free.fr/UNIX/48_R/all.html).
- Examples [here](http://rwiki.sciviews.org/doku.php).
- Typical [user wiki](http://www.statmethods.net/).

# Commands
```r
mydata = read.csv('/Users/pietra/projects/university/year3/cs3002/lab1/forestfires.csv', sep=',')

Expand Down

0 comments on commit 678c4fd

Please sign in to comment.