-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBegging and Tutorial
More file actions
69 lines (60 loc) · 2.37 KB
/
Begging and Tutorial
File metadata and controls
69 lines (60 loc) · 2.37 KB
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
### Script 1: disciplina "Introdução a Análises Macroevolutivas no R"
### some basic R language:
### files within R are called 'objects', exemple:
object_x <- 10**3/(45*5-45) # to run, use "Ctrl + r" or "Enter + r" or the "run" button up this box
object_y <- "You need study more" # for text (STRINGS), use quotation marks ("" or '')
print(object_x); print(object_y)
### functions use arguments within parenthesis
object_z <- c(1, 2, 3, 5, 6, 9, 120) # function "c()" is used for creating lists
### function "list()" is similar to function "c()" (also used for lists) but have a little diference
### if you print you can see the function LIST is have more details about the position of the element
### [[j]] = column
### [i] X = line with the X information
object_w <- list(1, 2, 3, 5, 6, 9, 120)
print(object_z); print(object_w)
### objects in R come in different "classes" use function "class()" to check
class(object_x)
class(object_y)
class(object_z)
class(object_w)
### use str() function to inspect "inside" objects (to inspect its STRucture)
str(object_x)
str(object_y)
str(object_z)
str(object_w)
### use $ symbol to show elements of an data.frame object (data.frame is a class)
### YOU CANT MAKE ARGUMENTS WITH DIFERENT NUMBERS OFS LINES IN THE COLUMNS...
object_a = data.frame("column_1"= c(1 ,2 , 3, 4, 5, 10, 5*8),
"column_2" = c(6, 7, 8, 9,"safe", "shit"),
"column_3" = c(11, 12, 13, 14, 15, 4/2, 3**8))
object_aa = list(c(1,2,4,5,10,5*8),c(6,7,8,9,"safe","shit"),c(11,12,13,14,15,4/2,3**8))
### use $ in objetct to select especific part of the object
object_a$column_1
object_a$column_2
object_a$column_3
object_b <- data.frame("column_1" = object_a$column_1,
"column_2" = object_a$column_2,
"column_3" = object_a$column_3)
print(object_a); print(object_b); print(object_aa)
### compare:
class(object_a)
class(object_b)
str(object_a)
str(object_a)
### the function "data.frame()" can also be used to convert objects of other
### classes to class "data frame" this can be useful for getting your data in the
### right format for some functions
# example
object_c <- data.frame(object_w)
object_c2 = dataframe(object_a)
object_c3 = list(object_a)
object_c4 = c(object_a)
### compare
class(object_c)
class(object_c2)
class(object_c3)
class(object_c4)
str(object_c)
str(object_c2)
str(object_c3)
str(object_c4)