FAQ
Have any way to write a funtion into a list ?

--
Nash - morrison at ibms.sinica.edu.tw

Search Discussions

  • Philipp Pagel at Feb 25, 2009 at 3:28 pm

    On Wed, Feb 25, 2009 at 11:11:51PM +0800, Nash wrote:
    Have any way to write a funtion into a list ?
    You can do that the same way you would use with any other object:
    foo <- function(x){x^2}
    foo(12) [1] 144
    a <- list(foo, 12, 'as')
    a
    [[1]]
    function(x){x^2}

    [[2]]
    [1] 12

    [[3]]
    [1] "as"


    cu
    Philipp

    --
    Dr. Philipp Pagel
    Lehrstuhl f?r Genomorientierte Bioinformatik
    Technische Universit?t M?nchen
    Wissenschaftszentrum Weihenstephan
    85350 Freising, Germany
    http://mips.gsf.de/staff/pagel
  • Uwe Ligges at Feb 25, 2009 at 3:32 pm

    Nash wrote:
    Have any way to write a funtion into a list ?

    Sure:

    A <- list(mean, var)
    A[[1]](1:2) # 1.5
    A[[2]](1:2) # 0.5

    Uwe Ligges


    --
    Nash - morrison at ibms.sinica.edu.tw

    ______________________________________________
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedFeb 25, '09 at 3:11p
activeFeb 25, '09 at 3:32p
posts3
users3
websiter-project.org
irc#r

3 users in discussion

Nash: 1 post Philipp Pagel: 1 post Uwe Ligges: 1 post

People

Translate

site design / logo © 2022 Grokbase