Hi:

This also works on your example data. Using the 'x' data frame from Jim
Holtman's post,

subset(transform(x, diffAB = A - B, diffCD = C - D), select = c('diffAB',
'diffCD'))
  diffAB diffCD
1   -0.6   0.10
2   -0.4   0.10
3   -0.4  -0.06

transform() allows you to do the subtractions in one line, and subset() is
used to select  the difference variables. Not necessarily a 'better'
solution, but rather another alternative.

If you need to be taking numerous differences between odd numbered and even
numbered columns of your data frame, then Jim's solution is ideal.

HTH,
Dennis

On Sun, Jan 30, 2011 at 5:32 PM, Ramya <ramya.vict...@gmail.com> wrote:

>
> Hi,
>
> I have a Dataframe.
>
> A       B      C       D
> 0.1    0.7   0.9   0.8
> 0.20  0.60 0.80  0.70
> 0.40  0.80  0.70 0.76
>
> I need a resultant dataframe
>
> (A-B)   (C-D)
> -0.6     0.1
> -0.40    0.1
> -0.40   -0.06
>
> Any suggestion would be of a great help
>
> Thanks
> Ramya
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Finding-a-Diff-within-a-Dataframe-columns-tp3247943p3247943.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]]

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

Reply via email to