Hi Marvin, One way to get around the problem with "sd" is to only process those columns of a data frame for which the variance is defined. It is an opportunity to show students how to write wrapper functions as well:
sd_num<-function(x) return(ifelse(is.numeric(x),sd(x),NA)) df<-data.frame(group=rep(0:1,each=5),value=1:10,name=LETTERS[1:10]) aggregate(df[,2:3],by=df[1],FUN="sd_num") Jim On Tue, Jul 2, 2019 at 3:47 AM Marvin Kiene <m...@maki-science.org> wrote: > > Hello dear helpers, > > I am currently running a small R-crash course for beginners at my > university, since I believe that there a far too few lectures about how to > use R. > > Thereby, I showed the '??' or 'help.search()' function to the students as > well as the 'aggregate()' function with 'FUN=sd'. > > > > The code worked fine for me - as usual (in version 3.5.1) - but not for the > students. Doing some research got me to the point, that in the current > version (3.6.0), > > 'aggregate' cannot use 'sd' for data.frames with mixed columns of factors > and numeric columns and throws an error (which is somewhat ok, since 'var()' > is not applicable for factors, of course) instead of putting 'NA's into the > respective columns like it does with 'FUN=mean' and like it does in the > former version(s). > > Is this a bug or a feature? It would be nice to work with it, the way I am > used to. Of course it is not difficult to work around this problem, but it > is somewhat strange, why it was changed that way (if this was intended). > > > > Additionally, the 'help.search()' always just gives the result: "No results > found", for all of my students. > > > > I didn't find any post about that issues so far, so I am not sure whether > this are known issues (but all of my 10 students had this problem). > > > > If this were intended changes, I would be interested, what the reason is and > whether there are direct workarounds (e.g. instead of using only numeric > columns), for those issues. > > Otherwise I am looking forward to a fixed version. > > > > Thanks in advance for your help! > > > > Kind regards, > > Marvin Kiene > > > > Doctoral Student > > Department of Animal Ecology I, AG Prof. Laforsch > > University of Bayreuth > > 95440 Bayreuth > > Germany > > > > > [[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. ______________________________________________ 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.