Thanks. It helped me a lot. Ramya
On Mon, Jan 31, 2011 at 6:56 AM, djmuseR [via R] < ml-node+3248651-1296211736-40...@n4.nabble.com<ml-node%2b3248651-1296211736-40...@n4.nabble.com> > wrote: > 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 <[hidden > email]<http://user/SendEmail.jtp?type=node&node=3248651&i=0>> > 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<http://r.789695.n4.nabble.com/Finding-a-Diff-within-a-Dataframe-columns-tp3247943p3248066.html?by-user=t> > > Sent from the R help mailing list archive at Nabble.com. > > > > ______________________________________________ > > [hidden email] > > <http://user/SendEmail.jtp?type=node&node=3248651&i=1>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]] > > ______________________________________________ > [hidden email] <http://user/SendEmail.jtp?type=node&node=3248651&i=2>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. > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://r.789695.n4.nabble.com/Finding-a-Diff-within-a-Dataframe-columns-tp3247943p3248651.html > To unsubscribe from Finding a Diff within a Dataframe columns, click > here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3247943&code=cmFteWEudmljdG9yeUBnbWFpbC5jb218MzI0Nzk0M3w4MzM3MzUxMzc=>. > > -- View this message in context: http://r.789695.n4.nabble.com/Finding-a-Diff-within-a-Dataframe-columns-tp3247943p3248820.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] ______________________________________________ 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.