forked from optixlab/CASI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplorations.Rmd
74 lines (62 loc) · 1.61 KB
/
explorations.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
title: "R Explorations"
output: html_notebook
---
In this notebook, I am exploring certain R concepts to help with a better understanding of the language. These code bits are also here for reference.
Index:
* Useful functions
- download files
* ggplot histogram
* Latex fundamentals
* t-statistic
## Resources
* http://www.statmethods.net/index.html
*
## Useful functions:
#### Setup
```{r}
library(readr)
library(magrittr)
library(tidyr)
library(data.table)
library(ggplot2)
```
#### Download url data
```{r comment="download"}
fetch_data <- function(data_url, type="delim") {
if (type=="delim") {
my_data <- read_delim(data_url, " ", escape_double = FALSE, trim_ws = TRUE)
} else if (type == "table") {
my_data <- read.table(data_url, sep=",", header=T)
} else if (type == "csv") {
my_data <- read.csv(data_url)
} else {
my_data = NULL
}
return(my_data)
}
```
#### Latex
#### Plotting
Some practice with creating and plotting dataframes in R
```{r}
df = data.frame(time = 1:10,
a = cumsum(rnorm(10)),
b = cumsum(rnorm(10)),
c = cumsum(rnorm(10))
)
dfm <- melt(df, id.vars = 'time', variable.name = 'series', value.name = 'meas')
# Two ways of plotting:
ggplot(dfm, aes(time, meas)) + geom_line(aes(color=series))
ggplot(dfm, aes(time, meas)) + geom_line() + facet_grid(series ~ .)
```
#### t-test (from help)
```{r}
## Classical example: Student's sleep data
plot(extra ~ group, data = sleep)
## Traditional interface
with(sleep, t.test(extra[group == 1], extra[group == 2]))
## Formula interface
t.test(extra ~ group, data = sleep)
#View(sleep)
```