forked from laser-institute/laser-orientation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorientation_code-a-long.R
114 lines (69 loc) · 2.37 KB
/
orientation_code-a-long.R
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# CODE- ALONG #######################
## 1. Programming Basics ###########
#####################
### a. Functions ####
#####################
mean()
max()
filter()
class()
round(3.14)
#' In the space below, use the round() function to
#' round 3.14 to the nearest whole number.
#' Run your code to see the result.
round(3.14)
######################
### b. Arguments #####
######################
#### args() function ###############
?mean()
?class()
#' Take a look at the arguments for the round() function.
?round()
#' Add an argument to the round() function to
#' round pi to the nearest 1 decimal places.
#' Remember to add a comma between arguments.
round(3.14, digits = 1)
#######################
### c. Objects ########
#######################
twenty <-20
twenty
thirty <- 20
thirty
forty <- 20
forty
new_data <- 20
new_data
13 <- 20 *4
13
x <- 20 *4
# Don't ever have names like TRUE/FALSE or NaN, inf, NA
#### <- Operator ##################
#' Assign a number between 1 and 10 to a new object call my_number.
#' Multiply my_number by 2 and save as my_product.
#' Type my_product and run to examine the contents.
my_number <- 5
my_product <- my_number * 2
my_product
########Other operators
#Pipe operator
#percent greater than percent
# %>%
#The original pipe operator, %>%, comes from the {magrittr} package but all packages in the tidyverse load %>% for you automatically, so you don’t usually load magrittr explicitly.
# |>
#Some labs will also use a very powerful |> operator called a pipe. Pipes are a powerful tool for combining a sequence of functions or processes.
#The pipe has become such a useful and much used operator in R that it is now baked into R using the new and simpler version of the pipe |> operator demonstrated in the following code chunk:
#####################
### d. Packages #####
#####################
#### install.packages() function ######
install.packages("tidyverse")
library(tidyverse)
?tidyverse
#' Run the following code to
#' install the readr package.
#did it work? Maybe you need to install first. You can also check if you package is loaded in the package pane.
#' Now use the library() function to load the readr package into R.
library(readr)
#' Use ? to check the help document for the readr package.