FlexPivot: creates a FlexTable by transposing variables

Description Usage Arguments Value Examples

View source: R/FlexPivot.R

Description

creates a FlexTable by transposing variables into observations.

Usage

1
2
3
FlexPivot(dataset, id, transpose, columns, columns.transpose = T,
  color = character(0), background.color = character(0), space.table = F,
  column.label = "Stat.")

Arguments

dataset

a tidy data.frame.

id

variable whose values are used to identify transposed variables

transpose

transpose each columns by transpose groups

columns

variables to transpose

columns.transpose

transpose also columns

color

optional, font color, named character vector, names are specifying which element of columns to colorize and values column names that contains color values to use.

background.color

optional, cell background color, named character vector, names are specifying which element of columns to colorize and values column names that contains color values to use.

space.table

add a space after each group

column.label

label for column name of stacked columns when columns.transpose is FALSE

Value

a FlexTable object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# load ggplot2
if( require("dplyr", quietly = TRUE) ){
	
	data = mtcars
	data = group_by(data, vs, am, gear, carb)
	data = summarise(data, avg = mean( mpg ), min = min( mpg ))

	data$avg_col = ifelse( data$avg < 17, "red", "black" )
	data$min_col = ifelse( data$min < 20, "gray", "purple" )
	
	data$avg = sprintf( "%.3f", data$avg)
	data$min = sprintf( "%.2f", data$min)
	
	
	ft = FlexPivot( dataset = data, space = FALSE, columns.transpose = TRUE, 
		id = c("gear", "carb"), transpose = c("vs", "am"), 
		columns = c("avg", "min"), 
		color = c("avg"="avg_col", "min" = "min_col") )
	print( ft )
	if( interactive() ) readline("Hit <Return> to see next FlexTable:")
	
	
	ft = FlexPivot( dataset = data, space = TRUE, columns.transpose = TRUE, 
			id = c("gear", "carb"), transpose = c("vs", "am"), 
			columns = c("avg", "min") )
	print( ft )
	if( interactive() ) readline("Hit <Return> to see next FlexTable:")
	
	
	ft = FlexPivot( dataset = data, space = FALSE, columns.transpose = FALSE, 
			id = c("gear", "carb"), transpose = c("vs", "am"), 
			columns = c("avg", "min") )
	print( ft )
	if( interactive() ) readline("Hit <Return> to see next FlexTable:")
	
	
	ft = FlexPivot( dataset = data, space = TRUE, 
			columns.transpose = FALSE, 
			id = c("gear", "carb"), 
			transpose = c("vs", "am"), 
			columns = c("avg", "min")
	)
	print( ft )
	
}

Example output

Loading required package: xtable
Loading required package: ReporteRs
Loading required package: ReporteRsjars
OpenJDK 64-Bit Server VM warning: Can't detect initial thread stack location - find_vma failed

Attaching package: 'rtable'

The following object is masked from 'package:ReporteRs':

    renderFlexTable


Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

FlexTable object with 11 row(s) and 10 column(s).
FlexTable object with 11 row(s) and 14 column(s).
FlexTable object with 22 row(s) and 7 column(s).
FlexTable object with 22 row(s) and 9 column(s).
Warning message:
system call failed: Cannot allocate memory 

rtable documentation built on May 29, 2017, 9:48 a.m.

Related to FlexPivot in rtable...