get.summary: Summarize continuous and dicrete variables.

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

View source: R/summary.fxns.R

Description

A vector based summary function. Provides a table with percentages for dicrete data. And median, mean, range or standard deviation for continuous data.

Usage

1
get.summary(var, type, var.n=NULL, type2="range")

Arguments

var

A vector, can be discrete(integer, character or factor) or continuous(numeric)

type

integer

type=1 if x is continuous

type=2 if x is dicrete

var.n

character, If a variable name is provided, it will add this to output.

type2

if type=2 specify whether you want range or standard deviation. default is - "range"

Details

Summary statistics are rounded to nearest 2 decimal points.

Value

if type=1 returns a character vector with summary information. length of the vector is equal to length of unique classes and NA if any.

if type=2 returns a character of length 1 with summary information. NAs are separated by ";"

Author(s)

Arshi Arora

See Also

get.summary2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#when type=1, data is discrete
set.seed(123)
x<-sample(1:3,50, replace=TRUE)
get.summary(x,type=1)
#        1         2         3
#"17(34%)" "15(30%)" "18(36%)"

#lets see with NAs
x[c(1,5,30)] = NA
get.summary(x,type=1)
#        1         2         3      <NA>
#"15(30%)" "15(30%)" "17(34%)"   "3(6%)"

#when type=2, data is continuous
set.seed(123)
x<-rnorm(50)
get.summary(x, type=2, type2="range")
#[1] "-0.07(-1.97-2.17); NA=0"

x[c(1,5,30)] = NA
#get.summary(x, type=2, type2="sd")
#[1] "-0.08(0.93); NA=3"

arorarshi/utilar documentation built on Feb. 13, 2021, 10:22 a.m.