[R] help with matrix creation

Jim Lemon bitwrit at ozemail.com.au
Fri Aug 11 14:20:15 CEST 2000


Jesus Maria Frias Celayeta wrote:

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

 exp.sim<-data.frame(experiment,simul=simul$simul[match(experiment$times,simul$times)])

Jim

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list