1. Learn
  2. /
  3. Courses
  4. /
  5. Helsinki Open Data Science

Connected

Exercise

Excluding observations

Besides missing values, there might be other reasons to exclude observations. In our human data, there are a few data points which have been computed from other observations. We want to remove them before further analysis.

The basic way in R to reference the rows or columns of a data frame is to use brackets ([,]) along with indices or names. A comma is used to separate row and column references. In the examples below, df is a data frame.

df[,] # select every row and every column
df[1:5, ] # select first five rows
df[, c(2, 5)] # select 2nd and 5th columns

Instructions

100 XP
  • Use tail() to print out the last 10 observations of human (hint: ?tail). What are the last 10 country names?
  • Create object last
  • Create data frame human_ by selecting rows from the 1st to last from human.
  • Define the rownames in human_ by the Country column