[R] Elegant way to transform dataframe?

From: Barry Rountree <rountree_at_uga.edu>
Date: Thu, 20 Nov 2008 02:39:29 -0500 (EST)


Hello,

I have a dataframe with columns like:

  parameter1 parameter2 metricname value

and I'd like to transform it into a dataframe with columns:

  parameter1 parameter2 metric1 metric2 metric3

where the values for each metric would be in the appropriate column. There are often multiple values for a given (parameter1, parameter2, metricname) triple. In this case, I want to use the minimum value.

A constant number of metrics is associated with each possible combination of parameters.

I've cobbled together code that performs this using nested loops and far too many variables. The number of metrics has now gone up by an order of magnitude and I'm looking for a more elegant way of doing this.

If anyone has a short bit of code that can deal with this, I'd really appreciate having a look.

Thanks much,

Barry



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. Received on Thu 20 Nov 2008 - 08:04:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 20 Nov 2008 - 09:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive