Rlangauge reshape syntax

Post on 14-Apr-2017

107 Views

Category:

Data & Analytics

0 Downloads

Preview:

Click to see full reader

Transcript

Slide 1

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

Slide 1

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.

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

Slide 4Part of the group of companies

4

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

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

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

Slide 7Part of the group of companies

7

Load RESHAPE Package in R

LOAD package

Slide 8Part of the group of companies

8

Installing RESHAPE Package in R

Slide 9Part of the group of companies

9

R-language: RESHAPE package : Melt data frame

Slide 10Part of the group of companies

10

R-language: RESHAPE package: melt data frame

top related