# Exercises for 2.5: Data manipulation

## Preliminaries

• load the driving.Rdata file.
• type head( driving ) to look at the first few observations
• load the following packages: lsr
load( "~/Work/Research/Rbook/workshop_dsto/datasets/driving.Rdata")
library(lsr)

## Exercise 2.5.1: Reshaping from wide to long

• use wideToLong() to make a long-form version of the driving data frame. Save the results to driving.2
• if you didn’t already give the within-subjects factor a meaningful name, repeat the command but this time use the within argument to specifiy a good name for it

## Exercise 2.5.2: Reshaping from long to wide

• use the longToWide() function to make a wide-form version of the driving.2 data frame that you created in 2.5.1. Save the results to driving.3

## Exercise 2.5.3: Cutting a continuous variable into categories

• use cut() to cut driving$age into 3 bins of approximately equal size (i.e. similar age ranges). Save the result to age.group.1. • use table() to look at how many people fall in the different age groups, and look at the category names to see how wide each of the age groups are. • use quantileCut() to cut driving$age into 3 bins of approximately equal frequency (i.e., similar number of people in each group). Save the result to age.group.2.
• use table() to look at how many people fall in the different age groups, and look at the category names to see how wide each of the age groups are.

## Exercise 2.5.4: Permuting factor levels

• print out driving$distractor and take note of the ordering of factor levels • use bars() to plot means and confidence intervals for RT at time 1 for each distractor • use permuteLevels() to reorder the factor levels for distractor. • print out driving$distractor to check that you have successfully reordered the groups, and now use bars() to redraw the plot.