Hi:

I won't speak for Jim, as he's more than capable of responding to this
himself, but I'll give it a shot:

(1) It's not just the 'double percent sign', it's that slash in between
them, too. Certain operators in R happen to be enclosed between two percent
signs.

%/% is the integer division operator in R; it returns the integer part of
the result:
> 10 %/% 2
[1] 5
> 9 %/% 2       # integer part of 4.5
[1] 4
> 11 %/% 2     # integer part of 5.5
[1] 5

%% is the modulo (remainder from integer division) operator in R:
> 10 %% 2
[1] 0
> 11 %% 2
[1] 1
> 12 %% 2
[1] 0

(2) The sapply() function is commonly used to apply a function across a
vector of arguments; e.g., many loops can be replaced with equivalent
sapply() statements. In this case, the sequence used as the first argument
of sapply() consists of the odd numbers up to the number of columns in the
matrix; for each element of that sequence, the function computes the
difference between that odd numbered column in the matrix and the adjacent
even numbered column to its right.

Henrique's solution does the same thing, except he uses a factor variable
(gl(2, 2)) to distinguish odd from even-numbered columns. It's useful to
look at both solutions for a general answer to the problem you posed.

HTH,
Dennis

On Sun, Jan 30, 2011 at 7:49 PM, Ramya <ramya.victory@gmail.com> wrote:

>
> Hi jholtman,
>
> Thanks a ton it just worked. if you dont mind can you explain the code it a
> little
> sapply(seq(from = 1, by = 2, length = ncol(x) %/% 2), function(a){
> +     x[[a]] - x[[a + 1]]
> + })
>
> wat is the purpose of double percent sign and is the sapply the function we
> generally use for the Dataframe?
>
> Thanks
> Ramya
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Finding-a-Diff-within-a-Dataframe-columns-tp3247943p3248066.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

