-
Notifications
You must be signed in to change notification settings - Fork 4
/
Functions.R
69 lines (48 loc) · 941 Bytes
/
Functions.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
# Functions
## Example of Code
name_of_func <- function(input1,input2,input3=45){
# Code execute
result <- input1 + input2
return(result)
}
sum(c(1,2,3))
help(sum)
# Ex. 1
hello <- function(name){
print(paste("Hello", name))
}
hello('Sammy')
# Ex. 2
add_num <- function(num1,num2){
print(num1+num2)
}
add_num(4,5)
# Example 3
add_num <- function(num1,num2){
my.sum <- num1 + num2
return(num1+num2)
}
result <- add_num(10,25)
print(result)
# Example 4
times5 <- function(num){
return(num*5)
}
print(times5(20))
# Example 5
times5 <- function(num){
my.result <- num * 5
return(my.result)
}
my.output <- times5(100)
print(my.output)
# Example 6
v <- "I'm a global variable"
stuff <- "I'm global stuff"
fun <- function(stuff){
print(v)
stuff <- "Reassign stuff inside of this function fun"
print(stuff)
}
fun(stuff)
print(stuff)