Get startedGet started for free

Selecting columns

Often it is convenient to work with only a certain column or a subset of columns of a bigger data frame. There are many ways to select columns of data frame in R and you saw one of them in the previous exercise: select() from dplyr*.

dplyr is a popular library for data wrangling. There is also a convenient data wrangling cheatsheet by RStudio to help you get started.

This exercise is part of the course

Helsinki Open Data Science

View Course

Exercise instructions

  • Access the dplyr library
  • Create object keep_columns
  • Use select() (possibly together with one_of()) to create a new data frame learning2014 with the columns named in keep_columns.
  • Look at the structure of the new dataset

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# lrn14 is available

# access the dplyr library
library(dplyr)

# choose a handful of columns to keep
keep_columns <- c("gender","Age","attitude", "deep", "stra", "surf", "Points")

# select the 'keep_columns' to create a new dataset
learning2014 <- "change me!"

# see the stucture of the new dataset

Edit and Run Code