I have a data frame in R with 100 variables (columns) and 100 observations (rows). Each row is a patient; the columns are different variables such as gender, height, body-mass index, etc. I know that I can easily compute summary estimates for all of my variables using the
Hmisc library like so (note that I am using the
veteran data set as an example).
library(Hmisc) data(veteran) describe(veteran)
For this data set, there is a variable,
trt, that can take two values. I would like to treat this as a categorical variable and stratify the describe function by this variable. That way I can know the summary information for all patients with a trt value of 1 and all patients with a trt value of 2.
I would like to quickly perform hypothesis tests to see if there is a significant difference between groups 1 and 2 for every other variable analyzed. For categorical variables, I'd like to automatically perform a Chi-sq test or Fisher's exact test. For continuous variables, I'd like to automatically perform a t test. And I want the code just to spit out some p values. Is there a way to do that?
Response to comment
My goal would be to use this code to easily compute what I would be putting into Table 1 of my manuscript, which will describe the baseline population characteristics. An example of such a table is here: http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4281814/table/OFU040TB1/
My table would only have two columns. One for trt group 1, the other for trt group 2. And I would just report the means or median values, with a measure of dispersion like SD or IQR, then a p value for difference.