R Programming Exercise 21
Easy Difficulty
"airquality.csv" consists of temperature readings from month of May to September. The Temperature column is 4th and Month column is 5th. Write a code which will take 5 random temperatures from each month. Then calculate its mean and standard deviation. Assume that you don't know how many temperature readings there are in each month.
See The following attached code.
#The file airquality already exists in R hence we can easily access it. View(airquality) #View the data attach(airquality) #Column Names are stored as variables. set.seed(100) #Now we collect five random temparatures M5=sample(subset(airquality,Month=="5")$Temp,size=5) M6=sample(subset(airquality,Month=="6")$Temp,size=5) M7=sample(subset(airquality,Month=="7")$Temp,size=5) M8=sample(subset(airquality,Month=="8")$Temp,size=5) M9=sample(subset(airquality,Month=="9")$Temp,size=5) #Now the collect all the sample points to form a single vector. Data=c(M5,M6,M7,M8,M9) #Finally we calculate the mean and Standard Deviation using the following command. mean(Data) sd(Data)
Get Answers For Free
Most questions answered within 1 hours.