Niklas Fischer
2013-Feb-25 18:04 UTC
[R] frequency table-visualization for complex categorical variables
Dear R users, I have three questions measuring close relationships. The questions are same and the respondents put the answer in order. I'd like to examine the pattern of answers and visualize it. For example q1 (A,B,C,D,E) and q2 and q3 are the same. If the respondents selects A B C (so BCA or BAC or CBA or CAB), I'd like to construct frequency table for ABC and other combinations for example DEF. Unfortunately, there are many answers, and three-way contingency table includes lots of cells which make it diffucult to interpret and requires lots of extra work to organize data. What is the best way to construct fruequency table of these kind of variables and to visulize the results with the most simple form All the bests, Niklas [[alternative HTML version deleted]]
Anthony Damico
2013-Feb-25 18:32 UTC
[R] frequency table-visualization for complex categorical variables
in the future, please provide R code to re-create some example data :) read http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-examplefor more detail.. # create a data table with three unique columns' values.. # treat these values just like letters x <- cbind( sample( LETTERS[1:6] , 100 , replace = TRUE ) , sample( LETTERS[1:6] , 100 , replace = TRUE ) , sample( LETTERS[1:6] , 100 , replace = TRUE ) ) # look at x.. this is good data i hope? x # convert this to a matrix y <- as.matrix( x ) # i don't think you care about ordering, so sort left-to-rightwards z <- apply( y , 2 , sort ) # look at your results z # paste these results together across the matrix w <- apply( z , 1 , paste0 , collapse = "" ) # count the final distinct results table( w ) On Mon, Feb 25, 2013 at 1:04 PM, Niklas Fischer <niklasfischer980@gmail.com>wrote:> Dear R users, > > I have three questions measuring close relationships. > The questions are same and the respondents put the answer in order. > > I'd like to examine the pattern of answers and visualize it. > > For example q1 (A,B,C,D,E) and q2 and q3 are the same. If the respondents > selects A B C (so BCA or BAC or CBA or CAB), I'd like to construct > frequency table for ABC and other combinations for example DEF. > > > Unfortunately, there are many answers, and three-way contingency table > includes lots of cells which make it diffucult to interpret and requires > lots of extra work to organize data. > > What is the best way to construct fruequency table of these kind of > variables and to visulize the results with the most simple form > > > All the bests, > Niklas > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]