Skip to content
Prev 248973 / 398506 Next

Finding a Diff within a Dataframe columns

I see that others have already responded, but will add my point of
view.  You indicated that you wanted to take the difference between
pairs of columns and did not specify exactly how many there were; in
your example there were 4 columns (2 pairs).  If there were only two,
then the solution from Dennis would be the way to go because it is
explicit in what has to be done.  I just created a list of the "odd"
columns [seq(from = 1, by = 2, length = ncol(x) %/%2)] trying to take
care of any odd number of columns.  This was then used in the 'sapply'
to iterate over the columns.
On Sun, Jan 30, 2011 at 10:49 PM, Ramya <ramya.victory at gmail.com> wrote: