[R] help converting code to a function

From: r user <ruser2006_at_yahoo.com>
Date: Sat 06 May 2006 - 01:45:27 EST

I want to write a function that loads a data frame from my hard drive, and then creates a new dataframe that calculates the difference between column n and column n+4, and them saves this new dataframe to my hard drive, and finally, removes both the new and old data frame from memory..

Here is the code I am using.

How do I convert this into a function that can be used to perform the same process on any dataframe?

load ('c:/r_pit/sampledf.r')
sampledf_yychg <-
data.frame(matrix(data=NA,nrow=l,ncol=w-4)) for(j in 1:(w-4)) { sampledf_yychg[, j]<-sampledf[, j]- sampledf[, j+4] }
save(sampledf_yychg, file='c:/r_pit/sampledf_yychg.r') rm(sampledf, sampledf_sq, sampledf_yychg)

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 06 01:59:04 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 06 May 2006 - 04:10:07 EST.

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