[R] specifying dataframe column names in loops
Simon Goodman
Simon.Goodman at ioz.ac.uk
Fri Jul 4 20:34:06 CEST 2003
Dear list members,
This is probably a naive question (from a new user), but I'm having problems
getting column
names to be recognised in loop that is supposed to apply a set of
calculations in turn
to each column of a dataframe.
The dataframe has 33 columns of output from a simulation.
The columns each have a text name and I want to apply the same set of
calculations
to each column in turn. These include some self-defined functions that refer
back to the
column in the current iteration.
Setting up a 'for' loop and using age[s] (where 'age' is the dataframe and
's' is the iterator) to specify
each column works for things like 'max' and 'min'. However for functions
like 'density' or locfit,
error messages are generated:
lf<-locfit(~age[s])
Error in model.frame(formula, rownames, variables, varnames, extras,
extranames, :
invalid variable type
Similary if I try to use the 'names' function.
lf<-locfit(~names(age[s]))
Error in model.frame(formula, rownames, variables, varnames, extras,
extranames, :
invalid variable type
So the question is how do I get functions like density or locfit to
work in the loop in the same they would for specifying the name
of the column directly e.g. d<-density(ACER), where ACER is the name of the
first column.
Many thanks, Simon Goodman....
-----------------------------------------------------------------------
_________________________________________________________________________
This e-mail has been sent in confidence to the named addressee(s).
If you are not the intended recipient, you must not disclose or distribute
it in any form, and you are asked to contact the sender immediately.
Views or opinions expressed in this communication may not be those
of The Zoological Society of London and, therefore, The Zoological
Society of London does not accept legal responsibility for the contents
of this message. The recipient(s) must be aware that e-mail is not a
secure communication medium and that the contents of this mail may
have been altered by a third party in transit.
If you have any issues regarding this mail please contact:
administrator at zsl.org.
More information about the R-help
mailing list