[R] row subtraction

Ista Zahn istazahn at gmail.com
Sun Oct 25 23:18:03 CET 2009

If I understand what you're asking this is one (although probably not
the easiest or best) way:

X <- as.data.frame(matrix(runif(50), nrow=10))

X.tmp <- rbind(rep(NA, dim(X)[2]), X[1:(dim(X)[1]-1),])

X.new <- X - X.tmp


On Sun, Oct 25, 2009 at 5:45 PM, Marsha Melnyk <mmelnyk at stevens.edu> wrote:
> I don't know if there is a way to do this in R but I want to subtract
> within the same column from different rows.  I want to subtract
> c(r)-c(r-1) and continue down the column until they are all calculated
> and form another column. Again I don't know if R can do this but I
> thought I would ask.
> Thanks either way
> ______________________________________________
> 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.

Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology

More information about the R-help mailing list