-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeworkWeek2.R
More file actions
24 lines (18 loc) · 895 Bytes
/
HomeworkWeek2.R
File metadata and controls
24 lines (18 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
even_numbers <- seq(2, 100, by = 2)
squares <- even_numbers^2
roots <- sqrt(even_numbers)
dataframe <- data.frame(even_numbers, squares, roots)
View(dataframe)
#Adding vectors: only vectors of same length can be added
one_to_ten <- 1:10
one_to_ten + 1000
#one_to_ten + c(1000, 2000, 3000)
#brexit dataset
# 1) What’s the mean percentage of Leave vote in a London constituency (variable region)?
mean_leave_london <- mean(brexit$leave_votes[brexit$region == "London"])
# 2) what’s the average Remain vote in areas classified as ‘Predominantly Rural’
avg_remain_rural <- mean(brexit$remain_votes[brexit$area_type == "Predominantly Rural"], na.rm = TRUE)
# 3) what’s the total number of Leave votes (leave_votes) across all local authorities?
# What’s the total number of Remain votes (remain_votes)?
total_leave = sum(brexit$leave_votes)
total_remain = sum(brexit$remain_votes)