On Jun 20, 2017, at 7:19 AM, Sorkin, John <jsorkin at som.umaryland.edu> wrote:
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)