Dear R Gurus: I read somewhere that functions are considered vectors. Is this true, please? thanks Edna Bell
On 3/19/2009 12:49 PM, Edna Bell wrote:> Dear R Gurus: > > I read somewhere that functions are considered vectors. > > Is this true, please?Your question is a little ambiguous (you probably did read that, and probably someone does consider them to be vectors), but I think the right answer is no: when the R documentation talks about vectors, it is not talking about functions, and the is.vector() function returns FALSE for functions. Duncan Murdoch
Edna: Please make at least a minimal effort to answer such questions before posting. is.vector(function(x)x) ## FALSE as.vector(function(x)x) ## try it or even is.vector(plot) -- Bert Gunter Genentech -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Edna Bell Sent: Thursday, March 19, 2009 9:50 AM To: r-help at stat.math.ethz.ch Subject: [R] function question Dear R Gurus: I read somewhere that functions are considered vectors. Is this true, please? thanks Edna Bell ______________________________________________ R-help at 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.
Functions and vectors are both objects in R, but a functions are not vectors try this foo<-function() print("I'm the foo function") is.vector(foo) as.vector(foo) Justin BEM BP 1917 Yaoundé Tél (237) 99597295 (237) 22040246 ________________________________ De : Edna Bell <edna.bell01@gmail.com> À : r-help@stat.math.ethz.ch Envoyé le : Jeudi, 19 Mars 2009, 17h49mn 32s Objet : [R] function question Dear R Gurus: I read somewhere that functions are considered vectors. Is this true, please? thanks Edna Bell ______________________________________________ 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]]
Duncan Murdoch wrote:> On 3/19/2009 12:49 PM, Edna Bell wrote: >> Dear R Gurus: >> >> I read somewhere that functions are considered vectors. >> >> Is this true, please? > > Your question is a little ambiguous (you probably did read that, and > probably someone does consider them to be vectors), but I think the > right answer is no: when the R documentation talks about vectors, it > is not talking about functions, and the is.vector() function returns > FALSE for functions. > > Duncan MurdochIt could be that you read that about S+ functions, where they can be thought of as (very special) vectors. R functions are different in this respect. Patrick Burns patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User")> > ______________________________________________ > R-help at 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. > >
In mathematics that is the case. That is vector v = (v_1, v_2, ..., v_n) can be considered to be the function which maps k to v_k but there is no real relation to this in terms of R classes and objects. On Thu, Mar 19, 2009 at 12:49 PM, Edna Bell <edna.bell01 at gmail.com> wrote:> Dear R Gurus: > > I read somewhere that functions are considered vectors. > > Is this true, please? > > thanks > Edna Bell > > ______________________________________________ > R-help at 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. >
Bert Gunter wrote:> Edna: > > Please make at least a minimal effort to answer such questions before > posting. > > is.vector(function(x)x) ## FALSE > as.vector(function(x)x) ## try it > > or even > > is.vector(plot) > >... or even the surprizing is.vector(vector) vQ
Not surprising at all -- expected! is.function(vector) ##TRUE -- Bert -----Original Message----- From: Wacek Kusnierczyk [mailto:Waclaw.Marcin.Kusnierczyk at idi.ntnu.no] Sent: Thursday, March 19, 2009 1:03 PM To: Bert Gunter Cc: Edna Bell; R help Subject: Re: [R] function question Bert Gunter wrote:> Edna: > > Please make at least a minimal effort to answer such questions before > posting. > > is.vector(function(x)x) ## FALSE > as.vector(function(x)x) ## try it > > or even > > is.vector(plot) > >... or even the surprizing is.vector(vector) vQ
of course! as some might suggest, i should have used times new sarcastic ;) vQ PS beware of vector(vector) and function(function) Bert Gunter wrote:> Not surprising at all -- expected! > > is.function(vector) ##TRUE > > -- Bert > > -----Original Message----- > From: Wacek Kusnierczyk [mailto:Waclaw.Marcin.Kusnierczyk at idi.ntnu.no] > Sent: Thursday, March 19, 2009 1:03 PM > To: Bert Gunter > Cc: Edna Bell; R help > Subject: Re: [R] function question > > Bert Gunter wrote: > >> Edna: >> >> Please make at least a minimal effort to answer such questions before >> posting. >> >> is.vector(function(x)x) ## FALSE >> as.vector(function(x)x) ## try it >> >> or even >> >> is.vector(plot) >> >> >> > > ... or even the surprizing > > is.vector(vector) > >