I am trying to transpose a dataframe by its first column using the by statement 
using the t function. When I use the by function, I get a message,

Error in FUN(X[[i]], ...) : could not find function "FUN"

I don't think I have a syntax error in my by statement because the by statment 
works using the print function.

Data and an executable example follows:

phonydata2 <- structure(list(INTRVNTN = c("CONTROL", "CONTROL", "CONTROL",
"MPR+NMES+HPRO", "CONTROL", "CONTROL", "CONTROL", "CONTROL",
"MPR+NMES+HPRO", "MPR+NMES+HPRO", "CONTROL", "CONTROL", "CONTROL",
"MPR+NMES+HPRO", "MPR+NMES+HPRO", "MPR+NMES+HPRO", "CONTROL",
"MPR+NMES+HPRO", "MPR+NMES+HPRO", "CONTROL", "MPR+NMES+HPRO",
"CONTROL", "CONTROL", "MPR+NMES+HPRO", "CONTROL", "CONTROL",
"CONTROL", "MPR+NMES+HPRO", "CONTROL", "MPR+NMES+HPRO", "MPR+NMES+HPRO",
"MPR+NMES+HPRO"), HGDOM1_MW1 = c(NA, NA, NA, NA, NA, NA, 17,
30, 27.5, 12, 16, 16, 14, NA, 33, NA, 12, 25, NA, NA, 6, NA,
13.5, 10, 1, NA, 12, 18, NA, NA, NA, NA), HGDOM1_W1 = c(8, NA,
NA, 4, NA, NA, 18, NA, 26.5, 22, 14, 8, NA, NA, 33, NA, 15, NA,
4, 9, 18, NA, 14, 16, 2, NA, 18, 15, NA, NA, NA, NA)), .Names = c("INTRVNTN",
"HGDOM1_MW1", "HGDOM1_W1"), class = "data.frame", row.names = c(NA,
-32L))

phonydata2

# This works
by(phonydata2[,2:3],phonydata2[,1],print)
# This gives and error message.
by(phonydata2[,2:3],phonydata2[,1],t)

Thank you,
John








John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to