Skip to content

Lists and functions in data.frame?

3 messages · Rainer M Krug, jim holtman

#
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

- -- 
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:      Rainer at krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkz/WSIACgkQoYgNqgF2egocEwCeIErcuxDxVa8RFs1SlWiY/hQp
T84An1XAtE3tFNKajBnGQngTig4srlIb
=6AG3
-----END PGP SIGNATURE-----
#
It sounds like you want to use a "list" instead of a dataframe,
especially if the elements are a different length.
[[1]]
[[1]]$fun
function (x)  .Primitive("sin")


[[2]]
[[2]]$fun
function (x)  .Primitive("cos")

[[2]]$val
[1] 42
On Wed, Dec 8, 2010 at 5:08 AM, Rainer M Krug <r.m.krug at gmail.com> wrote:

  
    
#
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/08/2010 11:22 AM, jim holtman wrote:
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".
OK - forget about the different length - I could convert the vectors to
lists, and store them as lists in the data.frame (if possible).
Sure - that would work, but I would prefer to have it in a data.frame.

Cheers,

Rainer
______________________________________________
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.
- -- 
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:      Rainer at 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-----