[R] Function to tabulate t-test (1) How can I get dependent variable name (2) How can I make data frame know to function

John Sorkin JSorkin at grecc.umaryland.edu
Mon Jan 7 15:44:31 CET 2013

Windows 7
R 2.12.1
I am trying to write a function (see sample code below) that will take the output of a t-test and produce results suitable for a table.
I have two questions
(1) You will note that the name of the outcome variable, which is "value" in the input is replaced by the string "outcome by class" in the data frame produced by my function. How can I make my function put the name of the variable being analyzed,, i.e "value" in the output data frame
(2) How can I pass the entire input data to the function so my call to the function will not have to be in its current ugly form, i.e.  
and instead could just be
x <- data.frame(value=rnorm(20)  ,sex=rep("Male",  20))
y <- data.frame(value=rnorm(20,4),sex=rep("Female",20))
data <- rbind(x,y)
temp <- t.test(value~sex,data=data)
row.names(v) <- NULL
Table1 <- function(outcome,class) {
temp <- t.test(outcome~ class)
mydf <- data.frame(dep=temp$data.name,
row.names(mydf) <- NULL
Thank you,
John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
Confidentiality Statement:
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. 

More information about the R-help mailing list