Skip to content
Back to formatted view

Raw Message

Message-ID: <14297847.post@talk.nabble.com>
Date: 2007-12-12T15:56:38Z
From: Dan Kelley
Subject: how to shorten elements in a data frame?
In-Reply-To: <14296509.post@talk.nabble.com>

In case anyone with a similar need comes across this thread, I am posting
below a solution to my problem, in which I construct a new data frame that
has the desired dimensions, instead of trying to change the dimensions of
the existing data frame.

<code>
	npt <- length(pt)
	# Step through each variable.
	data.names <- names(x$data)
	data.new <- as.data.frame(array(NA, dim=c(npt, dim(x$data)[2])))
	names(data.new) <- data.names
	for (datum.name in data.names) {
		if (datum.name != "pressure") {
			data.new[[datum.name]] <- approx(x$data[["pressure"]],
x$data[[datum.name]], pt)$y
		}
	}
	# Now replace pressure
	data.new[["pressure"]] <- pt
	res$data <- data.new
</code>


-- 
View this message in context: http://www.nabble.com/how-to-shorten-elements-in-a-data-frame--tp14296509p14297847.html
Sent from the R help mailing list archive at Nabble.com.