[R] how to optionally include variables in a data.frame at assignment
Jenny Bryan
jenny at stat.ubc.ca
Wed Jun 13 23:44:36 CEST 2007
I am creating a data.frame inside a function and the set of variables
to include depends on the current value of other variables. Is there
a way to accomplish this in the original assignment? Or must I first
create the core data.frame with the variables I always want and then
use if blocks to add other variables?
Basically, I'm hoping for something like this (which does not work):
newDat <- data.frame(x, y, if(zInclude) z else NULL)
Thanks, Jenny
More information about the R-help
mailing list