help with loop
Wacek Kusnierczyk wrote:
is your data a data frame or a matrix? do you want to compute the
differences columnwise, i.e., for each column independently? consider
this example:
# generate and display dummy data
(d = as.data.frame(replicate(3, sample(5))))
# compute successive differences columnwise
as.data.frame(apply(d, 2, diff))
apply(as.matrix(d), 2, diff)
haven't noticed the sum part; you can apply colSums to the above
resulting data frame or matrix, e.g.:
colSums(apply(d, 2, diff))
vQ