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
rm(list = ls()) # clears all variables
a = 3.2; b = 3 # double types
b
typeof(b) # function returns type of object
c = as.integer(b) # cast to integer type
c
typeof(c)
c = 3L # alternative to casting: L specifies integer
d = TRUE
d
e = as.numeric(d) # casting to numeric
e
f = "this is a string" # string
f
ls.str() # show variables and their types
# Factor variables assume values in a predefined set of possible values.
# The code below demonstrates the use of factors in R:
current.season = factor("summer",
levels = c("summer", "fall", "winter", "spring"),
ordered = TRUE) # ordered factor
current.season
levels(current.season) # display factor levels
my.eye.color = factor(
"brown",
levels = c("brown", "blue", "green"),
ordered = FALSE) # unordered factor
my.eye.color
Enter to Rename, Shift+Enter to Preview