-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBASICS.R
72 lines (42 loc) · 1.2 KB
/
BASICS.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
# This section is the program pane or script editor.
# The script editor is a great place to put code you care about.
# The bottom pane is the console. Here you can quickly expierment with code.
# Math
3 + 3
# Base R Functions + objects
# The <- symbols store the results of the operation to the right of them as an an object.
# This is called an assign statement
# Tip! Keyboard short cut is alt -
# Assign the result of 3+5 to X
result <- 3 + 5
result
# R is case senesitive!
Result
# You can perform operations on objects
result*10
# Combine these numbers into an array.
numbers <- c(1, 2, 3, 4, 5)
joe_daniel <- c("Joe", "Daniel")
# You can also combine objects
combined <- c(result,numbers)
# Using functions
seq(from = 0, to = 10, by = 2)
min(numbers)
max(numbers)
mean(numbers)
median(numbers)
first <- "Joseph"
middle <- "Daniel"
last <- "Noonan"
full_name <- paste(first, middle, last)
toupper(full_name)
# Custom Functions
# the function(x){} is how you start to right a function. X is the input.
# in this case to run the function you do add_pi(x), where x is what ever input you want
add_pi <- function(x){
x + 3.14
}
add_pi(x =3)
add_pi(x = result)
add_pi(3)
add_pi(result)