Dear Russ, Why not use simply
pH <- c(area1 = 4.5, area2 = 7, mud = 7.3, dam = 8.2, middle = 6.3) That notation is IMHO the most readable for students. Best regards, Thierry ---------------------------------------------------------------------------- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics & Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey > -----Oorspronkelijk bericht----- > Van: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] Namens Russ Abbott > Verzonden: zondag 20 maart 2011 6:46 > Aan: bill.venab...@csiro.au > CC: r-help@r-project.org > Onderwerp: Re: [R] R as a non-functional language > > I'm afraid I disagree. As a number of people have shown, > it's certainly possible to get the end result > > > pH <- c(4.5,7,7.3,8.2,6.3) > > names(pH) <- c('area1','area2','mud','dam','middle') > > pH > area1 area2 mud dam middle > 4.5 7.0 7.3 8.2 6.3 > > using a single expression. But what makes this non-functional > is that the > names() function operates on a reference to the pH > object/entity/element. In other words, the names() function > has a side effect, which is not permitted in strictly > functional programming. > > I don't know if R has threads. But imagine it did and that one ran > > > names(pH) <- c('area1','area2','mud','dam','middle') > > and > > > names(pH) <- c('areaA','areaB','dirt','blockage','center') > > in simultaneous threads. Since they are both operating on the > same pH element, it is uncertain what the result would be. > That's one of the things that functional programming prevents. > > *-- Russ * > > > > On Sat, Mar 19, 2011 at 10:22 PM, <bill.venab...@csiro.au> wrote: > > > PS the form > > > > names(p) <- c(...) > > > > is still functional, of course. It is just a bit of > syntactic sugar > > for the clumsier > > > > p <- `names<-`(p, c(...)) > > > > e.g. > > > pH <- `names<-`(pH, letters[1:5]) > > > pH > > a b c d e > > 4.5 7.0 7.3 8.2 6.3 > > > > > > > > > > > -----Original Message----- > > From: Venables, Bill (CMIS, Dutton Park) > > Sent: Sunday, 20 March 2011 3:09 PM > > To: 'Gabor Grothendieck'; 'russ.abb...@gmail.com' > > Cc: 'r-help@r-project.org' > > Subject: RE: [R] R as a non-functional language > > > > The idiom I prefer is > > > > pH <- structure(c(4.5,7,7.3,8.2,6.3), > > names = c('area1','area2','mud','dam','middle')) > > > > -----Original Message----- > > From: r-help-boun...@r-project.org > > [mailto:r-help-boun...@r-project.org] > > On Behalf Of Gabor Grothendieck > > Sent: Sunday, 20 March 2011 2:33 PM > > To: russ.abb...@gmail.com > > Cc: r-help@r-project.org > > Subject: Re: [R] R as a non-functional language > > > > On Sun, Mar 20, 2011 at 12:20 AM, Russ Abbott > <russ.abb...@gmail.com> > > wrote: > > > I'm reading Torgo (2010) *Data Mining with > > > R*<http://www.liaad.up.pt/~ltorgo/DataMiningWithR/code.html>in > > > preparation for a class I'll be teaching next quarter. Here's an > > > example that is very non-functional. > > > > > >> pH <- c(4.5,7,7.3,8.2,6.3) > > >> names(pH) <- c('area1','area2','mud','dam','middle') > > >> pH > > > area1 area2 mud dam middle > > > 4.5 7.0 7.3 8.2 6.3 > > > > > > > > > This sort of thing seems to be quite common in R. > > > > Try this: > > > > pH <- setNames(c(4.5,7,7.3,8.2,6.3), > > c('area1','area2','mud','dam','middle')) > > > > > > > > > > -- > > Statistics & Software Consulting > > GKX Group, GKX Associates Inc. > > tel: 1-877-GKX-GROUP > > email: ggrothendieck at gmail.com > > > > ______________________________________________ > > R-help@r-project.org mailing list > > 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. > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > 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 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.