R programming

aztecant
RProgrammingIntro1_Assignment_2_wk_2.pdf

Assignment 2 R Programming Introduction 1

This assignment relates to a data set containing weather information for Howick (Auckland, New Zealand) from Jan 1 2013 to Jan 9 2013.1

The data are provided in nine CSV files called "data20130101.csv" to "data20130109.csv" which are available from the Lesson 2 web site for this course. The first few lines of the first file are shown in Figure 1. Each row of data gives various weather-related values for a time during the day:

• The time (in 10 minute intervals). • The temperature (degrees Celsius) • The dewpoint (degrees Celsius) • The humidity (percentage) • The average wind speed (km/h) • The peak wind gust (km/h) • The average wind direction (degrees) • The total rainfall (mm) • The barometer pressure (hPa)

If you have not already done so in the previous assignment, download the files to a directory on your computer (remember to right-click and ”Save link as”; do NOT left-click on the links to the files).

time,temp,dew,hum,speed,gust,dir,rain,baro

00:00,14.1,11.1,82,0,0,0,0,1021

00:10,14.2,11.4,83,0,0,0,0,1021.3

00:20,14.2,11.4,83,0,0,0,0,1021.1

00:30,13.9,11.1,83,0,0,0,0,1020.9

00:40,13.7,11,84,0,0,0,0,1020.9

...

Figure 1: The first few lines of the first file in the weather data set.

1Obtained from http://howickweather.info/.

1

1. Write R code to generate 9 file names without using a for loop.

You should end up with a result that looks like this:

> files

[1] "data20130101.csv" "data20130102.csv" "data20130103.csv"

[4] "data20130104.csv" "data20130105.csv" "data20130106.csv"

[7] "data20130107.csv" "data20130108.csv" "data20130109.csv"

2. Write a for loop that reads in each file, calculates the maximum value for each file, and prints out a message for each file, as shown below:

The maximum value in file data20130101.csv is 1021.6

The maximum value in file data20130102.csv is 1019.5

The maximum value in file data20130103.csv is 1012

The maximum value in file data20130104.csv is 1012.9

The maximum value in file data20130105.csv is 1014.5

The maximum value in file data20130106.csv is 1012.9

The maximum value in file data20130107.csv is 1004.6

The maximum value in file data20130108.csv is 1011.8

The maximum value in file data20130109.csv is 1014.5

NOTE: that, as for Assignment 1, you will need to specify a value of 1 for the row.names argument in your function call to the read.csv() function (to specify that the first column of values in the CSV file should be treated as row names).

2