This exercise set provides (further) practice in writing Excel documents using the
xlsx package as well as importing and general data manipulation. Specifically we have loops in order for you to practice scaling. A previous exercise set focused on writing a simple sheet with the same package, see here.
We will use a subset of commuting data from the Dublin area from AIRO and the 2011 Irish census.
xlsx package. If necessary install it as indicated in the previous xlsx exercise set.
Download the data to your computer and read into your R workspace as
read.xlsx2() or the slower alternative
colClasses to set relevant classes as we will be manipulating the data later on.
Clean the data a bit by removing
'To_Work_School_College_' from the column names.
'population aged 5 and over' variables by electoral division name using for instance
data.table and save the result as
xlsx workbook object in your R workspace and call it
Create three sheets objects in
sheet1, sheet2, sheet3 in
wb and your workspace. Use a loop.
data.frame that lists proportion of respondents in each of the following category by electoral division: travel on foot, travel on bicycle, leave home before 6:30.
Add the top 5 electoral division in each category to a previously created sheets with all the proportions using a loop. Leave the first row free.
Add some great title to the first row of each sheet and apply some style to it.
Save your workbook to your working directory and open using Excel. Go back to
R and continue formatting and adding information to your workbook at will.
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below