-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02_BasicR.Rmd
92 lines (77 loc) · 1.33 KB
/
02_BasicR.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
title: "Basic R"
author:
- Isabel Fernandez Escapa, [email protected]
output:
rmdformats::robobook:
use_bookdown: true
code_folding: show
---
```{r klippy, echo=FALSE, include=TRUE}
klippy::klippy(c('r', 'bash'))
```
# Objects
```{r}
4+4
20 * 250
5^2
```
```{r}
x <- 4+4
#Look at the workspace!
x
#Look at the console!
x <- 4+10
y <- 5
```
```{r}
nums.vector <- c(7, 8, 45, 3, 2, 67)
cols.vector <- c("red", "blue", "green", "pink")
my.list <- list(x, y, nums.vector, cols.vector)
my.matrix <- cbind(x, y, nums.vector, cols.vector)
```
```{r}
class(nums.vector)
class(cols.vector)
class(my.list)
class(my.matrix)
```
```{r}
my.list
```
```{r}
my.matrix
```
# Data Frames and indexing
```{r}
mtcars #built-in data frame, go to the help window to learn about it
cars <- mtcars
```
```{r}
cars$mpg
```
```{r}
cars[,1]
```
```{r}
cars[17,]
```
# Data Import/Export
```{r}
mydata <- read.csv("data_input/Example01.csv")
mydata
```
```{r}
mydata$Average <-rowMeans(mydata[c("Bio.1", "Bio.2", "Bio.3","Bio.4")])
```
```{r}
library(tidyverse)
write_csv(mydata, "data_output/Example01_Edited.csv")
```
```{r}
write_rds(mydata, "data_output/Example01_Edited.rds")
mydata_Edited <- read_rds("data_output/Example01_Edited.rds")
```
# Learn more here
<https://r4ds.had.co.nz>
<https://rstudio.com/resources/cheatsheets/>