Week 1 Quiz

Question 16;  How many missing values are in the Ozone column of this data frame?

table1 <- read.csv('hw1_data.csv')
Ozone <- table1[ ,1]
is.na(Ozone)
> sum(isna)
[1] 37
> sum(!isna)

[1] 116



17 What is the mean of the Ozone column in this dataset? Exclude missing values (coded as NA) from this calculation.


 bad <- is.na(Ozone)

mean(Ozone[!bad])


18 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?

> table1 <- read.csv('hw1_data.csv')
> sub1<- table1[(table1$Ozone >31) & (table1$Temp > 90), ]
> sub1
     Ozone Solar.R Wind Temp Month Day
NA      NA      NA   NA   NA    NA  NA
NA.1    NA      NA   NA   NA    NA  NA
69      97     267  6.3   92     7   8
70      97     272  5.7   92     7   9
NA.2    NA      NA   NA   NA    NA  NA
NA.3    NA      NA   NA   NA    NA  NA
120     76     203  9.7   97     8  28
121    118     225  2.3   94     8  29
122     84     237  6.3   96     8  30
123     85     188  6.3   94     8  31
124     96     167  6.9   91     9   1
125     78     197  5.1   92     9   2
126     73     183  2.8   93     9   3
127     91     189  4.6   93     9   4
> good <- !is.na(sub1$Wind)
> sub2 <- sub1[good, ]
> sub2
    Ozone Solar.R Wind Temp Month Day
69     97     267  6.3   92     7   8
70     97     272  5.7   92     7   9
120    76     203  9.7   97     8  28
121   118     225  2.3   94     8  29
122    84     237  6.3   96     8  30
123    85     188  6.3   94     8  31
124    96     167  6.9   91     9   1
125    78     197  5.1   92     9   2
126    73     183  2.8   93     9   3
127    91     189  4.6   93     9   4
> > mean(sub2$Solar.R)
[1] 212.8





19. 

19 What is the mean of "Temp" when "Month" is equal to 6?

> mon6_data <- table1[table1$Month == 6, ]
> n02 <- which(mon6 == "TRUE")

> table1[n02, ]
 sub3 <- table1[n02, ]
mean(sub3$Temp)

20 What was the maximum ozone value in the month of May (i.e. Month is equal to 5)?

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值