Dear Researcher,

I have two data.frame and I wish to find a method to do mathematical
operation and obtain a new data.frame with a elegant code. I use a "long"
code and It runs but I want improve and I am searching a one string to do my
operation:


 exp1 <- data.frame(
 ID = c(1,1,1,1,2,2,3,2,1,2,2,1,3,1,3),
 v1=c(10,10,10,10,20,20,30,20,10,20,20,10,30,10,30))

exp2 <- data.frame(
 ID = c(2,2,1,3,1,1,3,2,1,2,3,1,1,1,2),
 v2=c(2,2,1,3,1,1,3,2,1,2,3,1,1,1,2))

exp1_or <-exp1[order(exp1$ID, decreasing = F, na.last = TRUE), ]
exp1_or

exp2_or <-exp2[order(exp2$ID, decreasing = F, na.last = TRUE), ]
exp2_or

allexp <- data.frame(exp1_or[,c(1,2)],exp2_or[,2])
str(allexp)
names(allexp)[3] = "v2"
str(allexp)

allexp$v3 <-  allexp$v1/allexp$v2

resultexp <- allexp[,c(1,4)]


second notes I use "order" to order ID value of exp1 and exp2. Is There a
function to order exp2 as exp1 (without modify the sequence of exp1)?

Thank always for your help and experience

Gianni

	[[alternative HTML version deleted]]

