[R] change attributes of all data.frame elements

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Feb 20 18:35:01 CET 2009


On Fri, 20 Feb 2009, Philipp Pagel wrote:

> On Fri, Feb 20, 2009 at 04:12:53PM +0000, Jarrod Hadfield wrote:
>> I was wondering whether there was an easy way to change the attributes
>> of all elements in a data.frame (rather than looping through elements)?
>>
>> Specifically, I would like to set the "dim" attributes to NULL
>
> Maybe I just don't really understand what you are after. The elements
> of a data.frame are vectors so by definition they only have one
> dimension. Furthermore, they are required to be the same length -
> otherwise it wouldn't be a proper data.frame, anymore.

Not so, they can be matrices or even data frames, and 'length' means 
NROW.  But arbitrarily removing dimensions does not seem wise.

In any case, anthing involving elments of a list (and a data frame is 
a list) is ulitimatly a list.

lapply(DF, as.vector)

might be as efficient a way as any to do this.

>
> So I guess you really want to accomplish something I didn't quite
> grasp. Could you give an example?

That would be a good idea -- an idea the posting guide has embraced.

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

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list