[R] compute differences
Henrique Dallazuanna
wwwhsd at gmail.com
Mon Sep 21 14:57:55 CEST 2009
Try this:
data.frame(ID = apply(expand.grid(x$ID, x$ID), 1, paste, collapse =
'-'), diff = c(outer(x$val, x$val, '-')))
On Mon, Sep 21, 2009 at 9:39 AM, alessandro carletti <alxmilton at yahoo.it> wrote:
> Hi,
> I have a problem.
> I have a data frame looking like:
>
> ID val
>
> A .3
> B 1.2
> C 3.4
> D 2.2
> E 2.0
>
> I need to CREATE the following TABLE:
>
> CASE DIFF
>
> A-A 0
> A-B -0.9
> A-C -3.1
> A-D -1.9
> A-E -1.7
> B-A ...
> B-B ...
> B-C
> B-D
> B-E
> C-A
> C-B
> C-C
> C-D
> C-E
> D-A
> D-B
> D-C
> D-D
> D-E
> E-A
> E-B
> E-C
> E-D
> E-E
>
> WHERE CASE IS THE COUPLE OF ELEMENTS CONSIDEREDM AND DIFF IS THE computed DIFFERENCE between their values.
>
> Could you give me suggestions?
>
> Alessandro Carletti
>
>
>
>
> ______________________________________________
> R-help at 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list