Re: [R] compute differences

2009-09-23 Thread jude.ryan
Alessandro Carletti 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

Re: [R] compute differences

2009-09-23 Thread Petr PIKAL
Hi You can use outer. If your data are in data frame test then DIFF - as.vector(t(outer(test$val, test$val, -))) returns a vector, You just need to add suitable names to rows. CASE - as.vector(t(outer(test$ID, test$ID, paste, sep=-))) data.frame(CASE, DIFF) will put it together. Regards

Re: [R] compute differences

2009-09-23 Thread jude.ryan
Thanks Petr! It is good to see multiple solutions to the same problem. Best, Jude -Original Message- From: Petr PIKAL [mailto:petr.pi...@precheza.cz] Sent: Wednesday, September 23, 2009 10:59 AM To: Ryan, Jude Cc: alxmil...@yahoo.it; r-help@r-project.org Subject: Re: [R] compute

[R] compute differences

2009-09-21 Thread alessandro carletti
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

Re: [R] compute differences

2009-09-21 Thread Henrique Dallazuanna
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 alxmil...@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 

Re: [R] compute differences

2009-09-21 Thread Julian Burgos
Here is an approach...probably there are more elegant ways mydata=data.frame(ID=c(A,B,C,D,E),val=c(.3,1.2,3.4,2.2,2.0)) index=expand.grid(1:nrow(mydata),1:nrow(mydata)) dif=data.frame(difference=mydata$val[index$Var2]-mydata$val[index$Var1])