[R] how to shorten elements in a data frame?

dankelley Dan.Kelley at dal.ca
Wed Dec 12 16:56:38 CET 2007


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.



More information about the R-help mailing list