Question

In: Statistics and Probability

R Programming Exercise Book Problem 39 (Problem Difficulty: Easy Thinking Question) Suppose you have an arbitrary...

R Programming Exercise Book

Problem 39 (Problem Difficulty: Easy Thinking Question)

Suppose you have an arbitrary data set "airquality.csv" which consists of a data of temperature in different months throughout the year. If you wanted to take 30 random temperature reading from each month and then calculate its mean and standard deviation, then how would you do it? Name the commands that you would use to solve this problem and explain in few words your logic to approach this problem.

Assumption: The temperature column is the fourth column in the data set and the month column is the fifth column in the data set. Also assume that you used read.csv("airquality.csv", nrows = 150, stringsAsFactors = FALSE) to read the data.

Solutions

Expert Solution

R-program and codes:

library(dplyr)

#Read csv file by browsing folder
daq_all<-read.csv(file.choose(),header = T)

#To see table of months and their data counts
table(daq_all$Month)

# We use 'for-loop' to do the task

# store months in the variable m
m=c(5,6,7,8,9)

# for loop

for(i in m){
# filter data for each month
daq<-filter(daq_all,Month==i)
  
# select sample of 30
sn<-sample_n(daq,30)
  
# Calculate mean
mean<-mean(sn$Temp)
  
# Calculate standard deviation
sd<-sd(sn$Temp)
  
# round the results to one decimal
mean<-round(mean,1)
sd<-round(sd,1)
  
# Print the results
print(paste('Month=',i))
print(paste('Mean',mean,'SD',sd))
}

R-output:


Related Solutions

R Programming Exercise Book Problem 31 (a) "airquality.csv" is a data set which consists of ozone,...
R Programming Exercise Book Problem 31 (a) "airquality.csv" is a data set which consists of ozone, solar radiation, wind and temperature measurements taken in New York city from May to September of 1973. Use the command read.csv to read the data set. Now write a code which will take 7 random temperature values from each month and then calculate the mean and the standard deviation for the 7 samples. Display the mean as a variables which includes the name of...
R Programming Exercise Book Problem 31 (a) "airquality.csv" is a data set which consists of ozone,...
R Programming Exercise Book Problem 31 (a) "airquality.csv" is a data set which consists of ozone, solar radiation, wind and temperature measurements taken in New York city from May to September of 1973. Use the command read.csv to read the data set. Now write a code which will take 7 random temperature values from each month and then calculate the mean and the standard deviation for the 7 samples. Display the mean as a variables which includes the name of...
THIS QUESTION IS BASED UPON JAVA PROGRAMMING. Exercise 1 In this exercise, you will add a...
THIS QUESTION IS BASED UPON JAVA PROGRAMMING. Exercise 1 In this exercise, you will add a method swapNodes to SinglyLinkedList class. This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same nodes, etc. Write the main method to test the swapNodes method. Hint: You may need to traverse the list. Exercise 2 In this exercise, you will...
INTELLECTUAL PROPERTY PROBLEM: Suppose you have an assessment for a programming course. You and your classmate...
INTELLECTUAL PROPERTY PROBLEM: Suppose you have an assessment for a programming course. You and your classmate have an established group chat were you discuss personal and academic issues and one day you saw that they are sharing code to each other. You verified with your friends participating in the exchange that they are completely identical. Did they perform academic dishonesty or have done acts against the Intellectual Property Code? Justify your answer. As a good friend and student, what course...
Question Objective: The objective of this lab exercise is to give you practice in programming with...
Question Objective: The objective of this lab exercise is to give you practice in programming with one of Python’s most widely used “container” data types -- the List (commonly called an “Array” in most other programming languages). More specifically you will demonstrate how to: Declare list objects Access a list for storing (i.e., writing) into a cell (a.k.a., element or component) and retrieving (i.e., reading) a value from a list cell/element/component Iterate through a list looking for specific values using...
R - STUDIO R PROGRAMMING STATISTICS Imagine that you and your friend have catched COVID-19 while...
R - STUDIO R PROGRAMMING STATISTICS Imagine that you and your friend have catched COVID-19 while jogging without social distancing. Your case is more severe than your friend’s at the beginning: there are 400 millions of coronavirus in you, and only 120 millions in your friend. However, your immune system is more effective. In your body the number coronavirus decrease by 20 percent each day (new = 0.8 × orginal), while in your friend it increases by 10 percent each...
Problem 39: You have just turned 30 years old, have just received your MBA, and have...
Problem 39: You have just turned 30 years old, have just received your MBA, and have accepted your first job. Now you must decide how much money to put into your RRSP. Your RRSP works as follows: Every dollar in the plan earns 7% per year. You cannot make withdrawals until your 65th birthday. After that point, you can make withdrawals as you see fit. You decide that you will plan to live to 100 and work until you turn...
Question 1: This question may be completed independently or as a group exercise. You have learned...
Question 1: This question may be completed independently or as a group exercise. You have learned that humans have 46 total chromosomes, and chimpanzees have 48 total chromosomes. Use other textbooks in biological anthropology and biology (or reputable online resources) to find the number of chromosomes in other organisms. Give an organism with considerably more chromosomes than humans. Give an organism with considerably fewer chromosomes than humans. Did your findings surprise you? What did your research suggest about the relationship...
Problem 2 You are thinking about getting a new grill for your backyard entertaining. You have...
Problem 2 You are thinking about getting a new grill for your backyard entertaining. You have a choice between a Weber Kettle Grill that uses charcoal and a Weber Gas Grill that operates on a natural gas feed from your house. The Kettle grill costs $290 and will last about 5 years. You estimate that you will use $185 worth of charcoal each year with the Kettle grill. The Gas Grill costs $950. It does not require charcoal, but you...
Monopoly behavior (Chapter 26 in the book) Problem 1. Suppose you want to open an amusement...
Monopoly behavior (Chapter 26 in the book) Problem 1. Suppose you want to open an amusement park. Your estimate of the daily attendance is 1000 people. Further, you expect that each person will demand x(p)= 50-50p rides, where p is the price per ride. All people are the same, and there cannot be negative rides. The marginal cost of a ride is zero. (a) What is each person’s inverse demand for rides? (b) How many rides per person will maximize...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT