-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions_2.R
104 lines (59 loc) · 1.62 KB
/
Functions_2.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
#Functions
download.file("https://ibm.box.com/shared/static/n5ay5qadfe7e1nnsv5s01oe1x62mq51j.csv", destfile="movies-db.csv")
ratings <- c(8.7, 6.9, 8.5)
mean(ratings)
sort(ratings)
printHelloWorld <- function(){
print("Hello World")
}
printHelloWorld()
add <- function(x, y) {
x + y
}
add(3, 4)
isGoodRating <- function(rating){
if(rating < 7){
return("NO")
}else{
return("YES")
}
}
isGoodRating(6)
isGoodRating(9.5)
# Baþlangýç deðeri olarak 7 verilirse
isGoodRating <- function(rating, threshold = 7){
if(rating < threshold){
return("NO")
}else{
return("YES")
}
}
isGoodRating(6)
isGoodRating(8, threshold = 8.5) # Baþlangýç deðeri deðiþtirilebilir.
my_data <- read.csv("movies-db.csv")
head(my_data)
akira <- my_data[my_data$name == "Akira", "average_rating"]
akira
isGoodRating(akira)
watchMovie <- function(data, moviename){
rating <- data[data["name"] == moviename,"average_rating"]
return(isGoodRating(rating))
}
watchMovie(my_data, "Akira")
watchMovie <- function(data, moviename, my_threshold){
rating <- data[data$name == moviename,"average_rating"]
return(isGoodRating(rating, threshold = my_threshold))
}
watchMovie(my_data, "Akira", 7)
watchMovie <- function(moviename, my_threshold = 7){
rating <- my_data[my_data[,1] == moviename,"average_rating"]
memo <- paste("The movie rating for", moviename, "is", rating) #Cümle oluþturma
print(memo)
return(isGoodRating(rating, threshold = my_threshold))
}
watchMovie("Akira")
myFunction <- function(){
y <<- 3.14 # Global deðiþken tanýmlama
return("Hello World")
}
myFunction()