FlexPivot: creates a FlexTable by transposing variables

Description Usage Arguments Value Examples

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 )
	
}

davidgohel/rtable documentation built on May 15, 2019, 1:12 a.m.