-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 12/08/2010 11:22 AM, jim holtman wrote: > It sounds like you want to use a "list" instead of a dataframe,
No - I would like to have a data,frame. I am aware of the differences, but as far as I understand, each column in a data.frame can have a differnt type. So I thought that the type of column fun could be "function", column no "list", column value "numeric" and column b "boolean". > especially if the elements are a different length. OK - forget about the different length - I could convert the vectors to lists, and store them as lists in the data.frame (if possible). > >> d <- list() # initialize >> d[[length(d) + 1]] <- list() # extend >> d[[length(d)]]$fun <- sin # add a function >> d[[length(d) + 1]] <- list() # extend again >> d[[length(d)]]$fun <- cos # another function >> d[[length(d)]]$val <- 42 # some value >> d > [[1]] > [[1]]$fun > function (x) .Primitive("sin") > > > [[2]] > [[2]]$fun > function (x) .Primitive("cos") > > [[2]]$val > [1] 42 Sure - that would work, but I would prefer to have it in a data.frame. Cheers, Rainer > > > On Wed, Dec 8, 2010 at 5:08 AM, Rainer M Krug <r.m.k...@gmail.com> wrote: > Hi > > I would like to have a data.frame, where one column contains functions, > and another one lists. i.e.: > > FUN <- function(l) {return(l$a+l$b+l$c} > LIST <- list(a=1, b=2, c=3) > > d <- data.frame(fun=FUN, no=LIST, value=2, b=TRUE) > > FUN <- function(l) {return(l$a*l$b*l$c} > LIST <- list(a=4, b=5, c=6) > > d <- rbind(d, data.frame(fun=FUN, no=LIST, value=2, b=FALSE) > > I would like > d$FUN[1](d$l[1] == 6 > to be TRUE > > I want to use it to save a parameterset for a simulation model, which > consists of functions, lists, and vectors of different length. > > Is this possible? > > > Cheers, > > Rainer > >> ______________________________________________ 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. >> - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel: +33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkz/YQEACgkQoYgNqgF2egoTSACfVeYcUqQZCXgxAEqWVw/bYmhm onUAoIXfDH7dFw+X8P7eEw7fX62cEUzf =YjUK -----END PGP SIGNATURE----- ______________________________________________ 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.