Microsoft Excel is perhaps the most popular data anlysis tool out there. While arguably convenient, spreadsheet software is error prone and Excel code can be very hard to review and test.
After successfully completing this exercise set, you will be able to prepare a basic Excel document using just R (no need to touch Excel yourself), leaving behind a reproducible R-script.
Solutions are available here.
Install and load the
xlsx package, using the
dependencies = TRUE option.
xlsx workbook object in your R workspace and call it
Create a sheet object in
iris assign it the name
sheet1 in your workspace.
Write the built-in Iris
data.frame to the iris sheet without row names. Hint: use the
Now you can write your workbook anytime to your working directory using
- Learn some of the differences between working in Excel with regression modelling and R
- Learn about different statistical concepts
- And much more
Apply ‘freeze pane’ on the top row.
Set width of columns 1 through 5 to 12, that is 84 pixels.
CB.setFont to make the header in bold.
Using tapply generate a table with the mean of ‘petal width’ by species and write to a new sheet called
pw, from row 2 down.
Add a title in cell
A1 above the table, merge the cells of the first three columns.
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.