describe: Description of variables

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Describes a vector or the columns in a matrix or data frame.

Usage

1
2
 describe(x,num.desc=c("mean","median","var","sd","valid.n"),xname=NA,
  horizontal=FALSE)

Arguments

x

A vector, matrix or data frame.

num.desc

The names of the functions to apply to numeric data.

xname

A name for the object x, mostly where this would be a very long string describing its structure (e.g. if it was extracted by name from a data frame).

horizontal

Whether to display the results of describe.factor across the page (TRUE) or down the page (FALSE).

Details

describe displays a table of descriptive statistics for numeric, factor and logical variables in the object x. The summary measures for numeric variables can easily be altered with the argument num.desc. Pass a character vector with the names of the desired summary measures and these will be displayed at the top of the numeric block with their results beneath them. If quantiles are desired, the user will have to write wrapper functions that call quantile with the appropriate type or probabilities and use the names of the wrapper functions in num.desc. Remember that any function called by describe must have an na.rm argument.

Percentages are now always displayed and returned in the tables for factor and logical variables.

Value

A list with three components:

Numeric

A list of the values returned from describe.numeric for each column described.

Factor

A list of the tables for each column described.

Logical

A list of the tables for each column described.

Author(s)

Jim Lemon

See Also

Mode, valid.n, describe.numeric, describe.factor

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 sample.df<-data.frame(sex=sample(c("MALE","FEMALE"),100,TRUE),
  income=(rnorm(100)+2.5)*20000,suburb=factor(sample(1:4,100,TRUE)))
 # include the maximum values
 describe(sample.df,num.desc=c("mean","median","max","var","sd","valid.n"))
 # make up a function
 roughness<-function(x,na.rm=TRUE) {
  if(na.rm) x<-x[!is.na(x)]
  xspan<-diff(range(x))
  return(mean(abs(diff(x))/xspan,na.rm=TRUE))
 }
 # now use it
 describe(sample.df$income,num.desc="roughness",xname="income")

Example output

Description of sample.df 

 Numeric 
           mean   median     max       var       sd valid.n
income 45979.72 45608.71 97482.2 327041105 18084.28     100

 Factor 
         
sex       FEMALE MALE
  Count       51   49
  Percent     51   49
Mode FEMALE 
         
suburb     2  3  4  1
  Count   29 25 25 21
  Percent 29 25 25 21
Mode 2 
Description of income 

 Numeric 
  roughness
x      0.21

prettyR documentation built on May 2, 2019, 2:16 a.m.

Related to describe in prettyR...