Combine Columns to Class

Usage

colcomb2class(dataframe, combined.columns, class = "list", percent = TRUE, digits = 2, elim.old = TRUE, zero.replace = 0, override = FALSE)

Arguments

dataframe
A dataframe or qdap class (e.g., termco, question_type, pos_by, character_table).
combined.columns
A list of named vectors of the colnames/indexes of the numeric columns to be combined (summed). If a vector is unnamed a name will be assigned.
class
The class to assign to the output.
percent
logical. If TRUE output given as percent. If FALSE the output is proportion.
digits
Integer; number of decimal places to round when printing.
elim.old
logical. If TRUE eliminates the columns that are combined together by the named match.list. TRUE outputs the table proportionally (see prop).
zero.replace
Value to replace 0 values with.
override
logical. If TRUE the printing options (e.g., percent, digits, etc.) of the dataframe argument are overrode.

Combine Columns to Class

Value

Returns a list with raw counts, percents and combined raw and percents.

Description

Combine columns from qdap classes or a data.frame.

Examples

## `termco` example ml <- list( cat1 = c(" the ", " a ", " an "), cat2 = c(" I'" ), "good", the = c("the", " the ", " the", "the") ) dat1 <- with(raj.act.1, termco(dialogue, person, ml)) colcomb2class(dat1, list(cats = c("cat1", "cat2")))
person word.count good the cats 1 Abraham 24 0 0 0 2 Benvolio 621 2(.32%) 44(7.09%) 34(5.48%) 3 Capulet 736 3(.41%) 30(4.08%) 42(5.71%) 4 First Citizen 16 0 3(18.75%) 2(12.50%) 5 First Servant 69 1(1.45%) 5(7.25%) 8(11.59%) 6 Gregory 149 0 16(10.74%) 9(6.04%) 7 Juliet 206 1(.49%) 9(4.37%) 6(2.91%) 8 Lady Capulet 286 0 21(7.34%) 20(6.99%) 9 Lady Montague 28 0 0 2(7.14%) 10 Mercutio 552 2(.36%) 46(8.33%) 49(8.88%) 11 Montague 217 1(.46%) 13(5.99%) 12(5.53%) 12 Nurse 598 2(.33%) 31(5.18%) 45(7.53%) 13 Paris 32 0 1(3.12%) 0 14 Prince 167 0 11(6.59%) 8(4.79%) 15 Romeo 1164 3(.26%) 48(4.12%) 59(5.07%) 16 Sampson 259 1(.39%) 23(8.88%) 19(7.34%) 17 Second Capulet 17 0 0 0 18 Second Servant 41 1(2.44%) 3(7.32%) 2(4.88%) 19 Servant 183 1(.55%) 12(6.56%) 13(7.10%) 20 Tybalt 160 0 10(6.25%) 12(7.50%)
## `question_type` example dat2 <- question_type(DATA.SPLIT$state, DATA.SPLIT$person) combs <- list( `wh/how` = c("what", "how"), oth = c("shall", "implied_do/does/did") ) colcomb2class(dat2, combs)
person tot.quest wh/how oth 1 greg 1 0 1(100%) 2 researcher 1 0 1(100%) 3 sally 2 2(100%) 0 4 teacher 1 1(100%) 0 5 sam 0 0 0
## `pos_by` example dat3 <- with(DATA, pos_by(state, list(adult, sex))) colcomb2class(dat3, qcv(DT, EX, FW))
adult&sex wrd.cnt IN JJ MD NN PRP PRP$ RB VB VBG VBP VBZ WP WRB 1 2 3 1 0.f 10 1(10.0%) 1(10.0%) 1(10.0%) 0 2(20.0%) 0 0 1(10.0%) 1(10.0%) 1(10.0%) 0 1(10%) 1(10%) 0 0 0 2 0.m 33 0 2(6.1%) 0 6(18.2%) 6(18.2%) 2(6.1%) 4(12.1%) 2(6.1%) 1(3.0%) 2(6.1%) 3(9.1%) 0 0 3(9.1%) 1(3.0%) 1(3.0%) 3 1.f 6 1(16.7%) 1(16.7%) 1(16.7%) 0 1(16.7%) 0 1(16.7%) 1(16.7%) 0 0 0 0 0 0 0 0 4 1.m 4 0 0 1(25.0%) 0 1(25.0%) 0 0 1(25.0%) 0 0 0 1(25%) 0 0 0 0
## data.frame example dat4 <- data.frame(X=LETTERS[1:5], matrix(sample(0:5, 20, TRUE), ncol = 4)) colcomb2class(dat4, list(new = c("X1", "X4")))
$raw X X2 X3 new 1 A 5 2 8 2 B 1 2 6 3 C 2 0 5 4 D 0 4 6 5 E 3 3 2 $prop X X2 X3 new 1 A 33.33333 13.33333 53.33333 2 B 11.11111 22.22222 66.66667 3 C 28.57143 0.00000 71.42857 4 D 0.00000 40.00000 60.00000 5 E 37.50000 37.50000 25.00000 $rnp X X2 X3 new 1 A 5(33.33%) 2(13.33%) 8(53.33%) 2 B 1(11.11%) 2(22.22%) 6(66.67%) 3 C 2(28.57%) 0 5(71.43%) 4 D 0 4(40.00%) 6(60.00%) 5 E 3(37.50%) 3(37.50%) 2(25.00%) $digits [1] 2 $percent [1] TRUE