0

I'm completely new to R, and I have a question that I think should not be very hard but is so for me.. I hope you can help me!

So I have a data frame with multiple data points from the same year (observations) and I have a data frama with only one data point from each year (modelled). Now I want to match the modelled data to right observational data.

Observed and modelled values can be seen in the link beneath the question!

This is the code I used to " pick out " the right values from the modelling:

Result <- matrix(nrow=length(Koutiala[,1]), ncol=1)
teller <- 1

if (Koutiala[1,1]==5) {
  Result[1,1] <- (Store[[2]]$soil$C$totalSoilC[5]/3000000)*100
  teller <- teller + 1
}

for(i in seq(1, length(Koutiala[,1]) , 1)) {  

  if (i %in% unique(Koutiala[,1])) {    
    Result[i] <- ((Store[[2]]$soil$C$totalSoilC[i]/3000000)*100)
    teller <- teller + 1}

  else {
    Result[i] <- NA}
}

Now I want to match for example Result[5] with Koutiala[1]; Result[6] with Koutiala[3]; Result[8] with Koutiala[4] etc...

Can anybody help me with this? I don't want do it manual because the dataset is actually very big!

Thank you so much, Renske

http://postimg.org/image/qi6e0ch8z/

Renske
  • 1
  • 1
  • 1
    I think you're looking for `merge`. It's usually better received if you provide a fake example of what you're trying to do. See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for some tips. – Roman Luštrik Jun 18 '14 at 13:57
  • Ok, thanks! I'll keep that in mind for next time :) Merge indeed does what I intended, however it creates a data frame with three rows, of which the last is just some complicated piece of code. Does this problem sound familiar by any chance? – Renske Jun 18 '14 at 14:17
  • Append what you've tried to the original question. Show us your object (`str()` and if possible, give us a working example. – Roman Luštrik Jun 18 '14 at 17:40

0 Answers0