[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] Finding a Diff within a Dataframe columns
From:       jim holtman <jholtman () gmail ! com>
Date:       2011-01-31 19:10:42
Message-ID: AANLkTimdkvLy_6QYjOLuEiZsPaNNzBRF4cEPFOrM7pXT () mail ! gmail ! com
[Download RAW message or body]

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@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.
> 



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

______________________________________________
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.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic