Is it o.k. to bootstrap sample of a table from its proportions - and how to do so (in R)? I wish to create a confidence interval for a statistic calculated on a table (let's say the p.value of chisqr.test).
For this, I might sample a bootstrap sample with the same size, from a table with the proportions of the table I have.  And my questions are:


*

*Is this a correct procedure to use, or is there some catch here that I might be missing?

*How can a table be "sampled" in R?  (my first instinct is to "open up" the table using melt, then expend the table to rows, sample them, and fold the results back to a table.  Is there a better way?)


p.s: I am aware of the "simulate.p.value" switch in chisqr.test - my question is more general - does it make sense to use bootstrap in such a way.
Sample table if someone wishes to show something:
(x <- matrix(c(12, 5, 7, 7), ncol = 2))
prop.table(x)

# undoing a table
as.data.frame(as.table(x)) # but how do we open up the rows now? - **update**: this was answered in the comments thanks to chl.

 A: Let me see if I understand you correctly:
You have a contingency table say $M$ by $N$ and you calculate a statistic based on this table. You want a CI for this statistic and you don't have a theoretical CI (or may be you don't want to use it, due to some reason). 
Generally, if you have a contingency table, the columns represent the possible levels of the response variable (here: $Y$ will have $N$ levels) and the rows represent the levels of the explanatory variables (here: $X$ will have $M$ levels). 
Now if you want to bootstrap, you need to make sure that you couple $Y$s and $X$s together. That is, shuffle $(X_i, Y_i)$ together for $i$ from $1$ to total number of observations (note this will be greater than $MN$ unless all the entries in the table are $1$).
Basically, what you can do is translate your table to a "hypothetical" data set set by using row numbers as levels for your $X$s and the column number as the value for the corresponding $Y$s.
To make it mathematically clear:
Lets say your $(i, j)^{th}$ entry in the table is $a$, then you need to create, $a$ data points for which the value of $Y$ is $j$ (remember column number for $Y$ value) and $X$ value is $i$. Do the same for $i = 1 \ldots m$ and $j = 1 \ldots n$. Now you have a "hypothetical" data set. Bootstrap from this data set as you would do in linear regression, say $B$ number of times. Each of the newly generated data set is a bootstrap sample. For each of the bootstrapped sample calculate the corresponding contingency table (say for $Y=1$ how many $X$s=1, how may $X$s=2, ... , this will give you the (1,1), (2,1),... entry for your table). Calculate the statistic for each of the $B$ tables and you have the desired bootstrap distribution.
I don't know if this is what you meant by bootstrapping the table. Please let me know if you thought otherwise.
HTH
S.
A: I once asked similar question on stackoverflow. Basically you sample from table the same way you sample vector. 
A: how to bootstrap a table ought to depend on how it was obtained. there are a few ways this can be done. 
for example, one can sample n individuals and classify all of them into an $r\times c$ table. in this scenario, neither row nor column totals are fixed. it would then seem plausible that a bootstrap sample would take a sample of size n  with replacement from the original n respondents and classify them into an $r\times c$ table.
in another scenario, the row totals for the table could have been fixed in advance. in that case, one would draw with replacement a sample of  $n_{i+}$ individuals from the $n_{i+}$ individuals in row $i$, separately for each row.
does this make sense? [apologies if this restates what has already been said. i don't quite grasp all of it.]
i would like to reiterate @whuber's query on why you are asking this question. one usually does not speak of obtaining a CI for a statistic [such as a p-value]. can you clarify this a bit?
