rtable (version 0.1.5)

FlexPivot: creates a FlexTable by transposing variables

Description

creates a FlexTable by transposing variables into observations.

Usage

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

Run this code
#
# 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 )
	
}

Run the code above in your browser using DataLab