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 2 0 8 2 B 5 4 2 3 C 0 1 4 4 D 0 1 3 5 E 0 4 1 $prop X X2 X3 new 1 A 20.00000 0.00000 80.00000 2 B 45.45455 36.36364 18.18182 3 C 0.00000 20.00000 80.00000 4 D 0.00000 25.00000 75.00000 5 E 0.00000 80.00000 20.00000 $rnp X X2 X3 new 1 A 2(20.00%) 0 8(80.00%) 2 B 5(45.45%) 4(36.36%) 2(18.18%) 3 C 0 1(20.00%) 4(80.00%) 4 D 0 1(25.00%) 3(75.00%) 5 E 0 4(80.00%) 1(20.00%) $digits [1] 2 $percent [1] TRUE