-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter-01.R
More file actions
57 lines (45 loc) · 1.3 KB
/
Copy pathchapter-01.R
File metadata and controls
57 lines (45 loc) · 1.3 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
#############################
# Project: R-Team meeting 01
# Purpose: Sample code for meeting one
# Author: Yevhen
# No external data files used
#############################
# Create an object with number of states with legal medical marijuana in 2017
states <- 29
kIllegalNum <- as.integer(21)
kStates <- states
# Rhode Island limit for medical marijuana in ounces per person
kOuncesRhode <- 2.5
rm(states)
# print the value
states
# determine how many states there would be if 2 more passed this policy
2 + states
kIllegalNum - 2
class(kIllegalNum)
class(kOuncesRhode)
# logical data type
kLogical <- TRUE
kLogical02 <- 6 > 4
# character data type
kChar01 <- "Some text in quotes"
kChar02 <- "1234121234"
# vector data type
char.vector <- c('Oregon', 'Vermont', 'Maine')
nums.1.to.4 <- c(1, 2, 3, 4)
logic.vector <- c(TRUE, FALSE, TRUE, TRUE)
# operations with vectors
nums.1.to.4 + 3
nums.1.to.4 + c(1,2,3,4)
nums.1.to.4 * 5
# matrix
(policies <- matrix(data <- c(1,2,3,4,5,6), nrow = 2, ncol = 3, byrow = TRUE))
dimnames(x = policies) <- list(
c("2013","2014"),
c("medical","recreational","both")
)
# data frames
state <- c("Alaska", "Arizona", "Arkansas", "California", "Colorado")
year <- c('1998', '2010', '2016', '1996', '2000')
ounce.lim <- c(1, 2.5, 3, 8, 2)
pot.legal <- data.frame(state, year, ounce.lim)