-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathRProgramming_Quiz_1.R
66 lines (50 loc) · 1.8 KB
/
RProgramming_Quiz_1.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
## R Programming Quiz 1
#load quiz data
data <- read.csv("C:/Users/jeffthatcher/Cloud Drive/CourseERA/2_R_Programming/hw1_data.csv")
#In the dataset provided for this Quiz, what are the column names of the dataset?
colnames(data)
#Extract the first 2 rows of the data frame and print them to the
# console. What does the output look like?
data2 <- data[1:2,]
data2
#How many observations (i.e. rows) are in this data frame?
tail(data)
nrow(data)
#Extract the last 2 rows of the data frame and print them
# to the console. What does the output look like?
data3 <- data[152:153,]
data3
data3 <- tail(data,2)
data3
#What is the value of Ozone in the 47th row?
data$Ozone[47]
#How many missing values are in the Ozone column of this data frame?
missingNA <- is.na(data$Ozone)
as.numeric(missingNA)
sum(missingNA)
missingNAN<- is.nan(data$Ozone)
as.numeric(missingNAN)
sum(missingNAN)
ozone_data <- data[,1]
length(ozone_data[is.na(ozone_data)]
#What is the mean of the Ozone column in this dataset? Exclude
# missing values (coded as NA) from this calculation.
Ozone <- na.omit(data$Ozone)
as.numeric(Ozone)
mean(Ozone)
ozone <- data[,1]
ozone_clean <- ozone[!is.na(ozone)]
mean(ozone_clean)
#Extract the subset of rows of the data frame where Ozone values are above 31 and Temp
# values are above 90. What is the mean of Solar.R in this subset?
data.subO <- data[data$Ozone > 31, , drop = FALSE]
data.subTO <- data.subO[data.subO$Temp > 90, , drop = FALSE]
data.subTOO <- na.omit(data.subTO)
mean(data.subTOO$Solar.R)
#What is the mean of "Temp" when "Month" is equal to 6?
data.June <- data[data$Month == 6, , drop = FALSE]
mean(data.June$Temp)
#What was the maximum ozone value in the month of May (i.e. Month = 5)?
data.May <- data[data$Month == 5, , drop = FALSE]
data.MayO <- na.omit(data.May)
max(data.MayO$Ozone)