10
Confidential Weekly Technology Update Slide 1 R-Language: Using ‘Reshape’ Package for partial Transpose (Stacking) of Data Set ROWs Phil Lau. 9 th August 2015 Slide 1

Rlangauge reshape syntax

Embed Size (px)

Citation preview

Page 1: Rlangauge reshape syntax

Slide 1

R-Language: Using ‘Reshape’ Package for partial Transpose (Stacking) of Data Set ROWsPhil Lau. 9th August 2015

Slide 1

Page 2: Rlangauge reshape syntax

Slide 2Part of the group of companies

2

R: Transposing (Stacking) Data Set ROWs

1. Assumption: R statistical software has been install: http://www.stats.bris.ac.uk/R/

2. R Home Page: https://www.r-project.org/

3. ** Example Program on slide 4 (results on slide 5) **.

4. For this presentation, R package RESHAPE(2) needs to be installed. See slides 7, 8

• Sometimes we are presented with data (data set, data frame, excel table) were some rows need to be converted into a column (transpose), or stacked, under a label heading (a variable) to be consider for data analysis or use in EXCEL PIVOT Chart.

• There is, also, times when only a subset within a data set needs stacking. R package, RESHAPE’s melt() function addresses this.

Page 3: Rlangauge reshape syntax

Slide 3Part of the group of companies

3

Transpose matrix Summary:

Slide 4 Shows a R script file for processing a typical excel CSV table, dfSlide 5 shows result of transposing, partially, this table.Slide 6 shows alternative approach to transposing

Page 4: Rlangauge reshape syntax

Slide 4Part of the group of companies

4

R Environment: Using Melt() function for transposing data set df

Page 5: Rlangauge reshape syntax

Slide 5Part of the group of companies

5

Before & After Transposing (stacking – partial) dataset ‘df’ – using melt()

Data Table After Transposing

Data Table Before Transposing

‘Value’ should be output ‘outcome’

‘id’ argument used to state which heading parameters not to be stacked

Page 6: Rlangauge reshape syntax

Slide 6Part of the group of companies

6

ALTERNATIVE: Before & After Transposing dataset df – using melt()

‘measure‘ argument used explicitly for converting Column headings to rows with values

Data Table Before Transposing

Data Table After Transposing

Value should be outcome

Page 7: Rlangauge reshape syntax

Slide 7Part of the group of companies

7

Load RESHAPE Package in R

LOAD package

Page 8: Rlangauge reshape syntax

Slide 8Part of the group of companies

8

Installing RESHAPE Package in R

Page 9: Rlangauge reshape syntax

Slide 9Part of the group of companies

9

R-language: RESHAPE package : Melt data frame

Page 10: Rlangauge reshape syntax

Slide 10Part of the group of companies

10

R-language: RESHAPE package: melt data frame