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]]
> 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)It only gives an error message if you redefined `t`. It runs perfectly fine in there is no data-object in your workspace named `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 at 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.David Winsemius Alameda, CA, USA
Hello, Works fine also with me: > by(phonydata2[,2:3],phonydata2[,1],t) phonydata2[, 1]: CONTROL 1 2 3 5 6 7 8 11 12 13 17 20 22 23 25 26 27 29 HGDOM1_MW1 NA NA NA NA NA 17 30 16 16 14 12 NA NA 13.5 1 NA 12 NA HGDOM1_W1 8 NA NA NA NA 18 NA 14 8 NA 15 9 NA 14.0 2 NA 18 NA ------------------------------------------------------------ phonydata2[, 1]: MPR+NMES+HPRO 4 9 10 14 15 16 18 19 21 24 28 30 31 32 HGDOM1_MW1 NA 27.5 12 NA 33 NA 25 NA 6 10 18 NA NA NA HGDOM1_W1 4 26.5 22 NA 33 NA NA 4 18 16 15 NA NA NA > > t <- 1:10 > by(phonydata2[,2:3],phonydata2[,1],t) Error in FUN(data[x, , drop = FALSE], ...) : could not find function "FUN" > > sessionInfo() R version 3.4.0 (2017-04-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 Matrix products: default locale: [1] LC_COLLATE=Portuguese_Portugal.1252 LC_CTYPE=Portuguese_Portugal.1252 [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Portugal.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.4.0 Hope this helps, Rui Barradas Em 20-06-2017 17:18, David Winsemius escreveu:> >> 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) > > It only gives an error message if you redefined `t`. It runs perfectly fine in there is no data-object in your workspace named `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 at 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. > > David Winsemius > Alameda, CA, USA > > ______________________________________________ > R-help at 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. >
Possibly Parallel Threads
- by can not find transpose function
- Loading data into a list of environments
- How do I include a factor in a groupedData object? Meaning and use of inner and outer parameters
- How do I include a factor in a groupedData object? Meaning and use of inner and outer parameters
- Function to recognise convert dates between gregorian and other calendars (e.g. Persian)?