12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

When converting data between long and wide formats, it’s important to beable to distinguish identifier variables from measured variables:Identifier variables: Identifier, or ID, variables identify the observations. Thinkof these as the key that identifies your observations. (In database design, theseare called primary or secondary keys.)Measured variables: This represents the measurements you observed.In our example, the identifier variables are Game and Venue, while themeasured variables are the goals (that is, the columns Granny, Geraldine, andGertrude).Getting started with the reshape2 packageBase R has a function, reshape(), that works fine for data reshaping. However,the original author of this function had in mind a specific use case for reshaping:so-called longitudinal data.Longitudinal research takes repeated observations of a research subjectover a period of time. For this reason, longitudinal data typically has thevariables associated with time.The problem of data reshaping is far more generic than simply dealing withlongitudinal data. For this reason, Hadley Wickham wrote and released thepackage reshape2 that contains several functions to convert data between long andwide format.To download and install reshape2, use install.packages():> install.packages(“reshape2”)At the start of each new R session that uses reshape2, you need to load thepackage into memory using library():> library(“reshape2”)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!