R for Everyone
  1. Foundations & Objects
  2. 5  R objects exercises
  • Start
    • 1  Introduction
  • Foundations & Objects
    • 2  Foundations of R
    • 3  Foundations of R exercises
    • 4  R objects
    • 5  R objects exercises
    • 6  R objects solutions
  • Files, Subsetting, & Tips
    • 7  Files and subsetting data
    • 8  Files exercises
    • 9  Files solutions
    • 10  Handy tips & tricks
    • 11  Handy exercises
    • 12  Handy Solutions
  • Plots
    • 13  Histograms and Line graphs
    • 14  Scatter plots and Box plot
    • 15  Plots exercises
    • 16  Plots solutions
  • Stats & Programming
    • 17  Basic stats
    • 18  Stats exercises
    • 19  Stats solutions
    • 20  Basic programming
    • 21  Student grades example
  • Appendices
    • A  Further resources

In this chapter

  • 5.1 df
  • 5.2 beach_df_2

5  R objects exercises

For this exercise simply produce the following tables as data frames in R. Please carry this out in your “Exercises.R” script and remember about code sections and annotations.

Tip: You can either write completely new code or reuse and alter previous code.

5.1 df

Note: The top row is the column names and the left-most column is the row names.

One Three Five
Two 2 6 10
Four 4 12 20
Six 6 18 30

5.2 beach_df_2

Note: The top row is the column names and the left-most column is the row names.

Crab Oystercatcher Sandpiper Starfish
Formby 10 5 1 3
West Kirby 1 6 1 3
Crosby 1 4 2 7
New Brighton 4 4 3 4
4  R objects
6  R objects solutions