[R] help with matrix creation

Jesus Maria Frias Celayeta iosu at bureau.ucc.ie
Fri Aug 11 00:33:39 CEST 2000


hi R-help!

    I would like to know a simple and easy way (if posible) to do the following
data manipulation. I have a matrix of experimental data (with replicae in time)

>experiment<-data.frame(times=c(0,0,10,10,20,20,30,30),expval=c(1,1,2,2,3,3,4,4))

> experiment
  times expval
1     0      1
2     0      1
3    10      2
4    10      2
5    20      3
6    20      3
7    30      4
8    30      4

and a set of simulated values

> simul<-data.frame(times=c(0,10,20,30),simul=c(3,4,5,6))
> simul
  times simul
1     0     3
2    10     4
3    20     5
4    30     6

>From this simulated data, I would like to obtain a data frame like this

  times expval simul
1     0      1     3
2     0      1     3
3    10      2     4
4    10      2     4
5    20      3     5
6    20      3     5
7    30      4     6
8    30      4     6

expanding each of the simulated values as many times as duplicates (triplicates
or anything) I have in the data. I have come across duplicate and match, but I
don't see a way forward from here, unless I make a for loop and I match row by
row the time vectors. I am sure that is a very easy thing, and I apologize in
advance for the stupid question, but I am kind of stuck.

cheers,

IOsu



-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000810/d8e9521e/attachment.html


More information about the R-help mailing list