|||

rbind.fill for 1-dimensional tables in r

The problem

I have two one-dimensional frequency tables resulting from say the baseline and endline of a survey, recording say membership of 5 age groups. The levels of the two variables should be the same but they might not be, say if at endline there was no-one in one of the age groups.

0-10 11-20 21-30
baseline 3 9 22
endline 0 6 12

I want to merge these into one table. The data comes out of some survey software so the two variables aren’t factors. The endline variable doesn’t know there is a missing level, so the one-dimensional frequency table is just this:

11-20 21-30
6 12

I know of no elegant way to do this. You can only use rbind if the names of the two tables are the same. If the two tables were data.frames, you could use rbind.fill from plyr, otherwise a nice function but not helpful in the one-dimensional case.

In the end I wrote a function:

rbind1dtable=function(tab1,tab2,fail=0){
  sapply(union(names(tab1),names(tab2)),function(n){
    t1=tab1[which(names(tab1)==n)]
    t2=tab2[which(names(tab2)==n)]
    c(ifelse(length(t1)==0,fail,t1),ifelse(length(t2)==0,fail,t2))
  })
}
Up next yED graph editor Here I’m going to make some notes about using yED graph editor for Theory of Change diagrams. I’ll add to it as I find out more. TL;DR: Seems like a Answering the “why” question: piecing together multiple pieces of causal information ((This is an abstract I just submitted to the 2019 DGeval conference in Bonn.)) We evaluators often ask questions about what causes what — because
Latest posts Causal Map intro Causal Mapping - an earlier guide The walk to school in Sarajevo Glitches Draft blog post for AEA365 Theory Maker! Inventory & analysis of small conservation grants, C&W Africa - Powell & Mesbach! Lots of charts! Answering the “why” question: piecing together multiple pieces of causal information rbind.fill for 1-dimensional tables in r yED graph editor Examples of trivial graph format Using attr labels for ggplot An evaluation puzzle: “Talent show” An evaluation puzzle: “Mobile first” An evaluation puzzle: “Many hands” An evaluation puzzle: Loaves and fishes An evaluation puzzle: “Freak weather” An evaluation puzzle: “Billionaire” Publications Using Dropbox for syncing Shiny app data on Amazon EC2 Progress on the Causal Map app Articles and presentations related to Causal Maps and Theorymaker Better ways to present country-level data on a world map: equal-area cartograms A starter kit for reproducible research with R A reproducible workflow for evaluation reports Welcome to the Wiggle Room Realtime comments on a Theory of Change Responses to open questions shown as tooltips in a chart A panel on visualising Theories of Change for EES 2018? Peer mentoring for evaluators How do you explain reproducible research to clients?