Skip to content
Prev 131925 / 398506 Next

how to shorten elements in a data frame?

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>