0

I've got the following problem: I have to calculate the volume of specific trees. Therefore I need all the diametres and heights for each tree.
I put these variables then into land specific equations.

After that, I want to summarize all the data into one dataframe. But the results should have the land ID as well. At the moment I've come up with this solution:

volPs <- data.frame(
land    = c("Sweden"),
dbh     = c(dbhPs),
h       = c(hPs),
calcVol = c(volSwedenPs)

)
volPs <- rbind(volPs, data.frame(land = "Estonia", dbh = c(dbhPs), 
                                 h = c(hPs), calcVol = c(volEstoniaPs)))
volPs <- rbind(volPs, data.frame(land = "Slovenia", dbh = c(dbhPs), 
                                 h = c(hPs), calcVol = c(volSloveniaPs)))
volPs <- rbind(volPs, data.frame(land = "Czech", dbh = c(dbhPs), 
                                 h = c(hPs), calcVol = c(volCzechPs)))
volPs <- rbind(volPs, data.frame(land = "Brandenburg", dbh = c(dbhPs), 
                                 h = c(hPs), calcVol = c(volBrandenburgPs)))
volPs <- rbind(volPs, data.frame(land = "Reported values", 
                                 dbh = c(dbhPs), h = c(hPs), 
                                 calcVol = c(df2$tv[df2$cts==codePs & 
                                                   df2$dbh > 0 & df2$h > 0])))
volPs <- rbind(volPs, data.frame(land = "Austria", 
                                 dbh = c(dbhPs), h = c(hPs), 
                                 calcVol = c(volAustriaPs)))

As you can see, I create the data.frame with one set of data at first. And then adding land by land to get the land into the right set of data.
This works perfectly but I've got the feeling that this is a very bad way to solve this problem.

Is there a better way to merge the data while adding a land specific row as well?
Thank you guys in advance.

tbradley
  • 2,210
  • 11
  • 20
milk
  • 3
  • 2
  • One intermediate step would be to put the country data.frames in a list: `myList <- list(Estonia=data.frame(land = "Estonia", dbh = c(dbhPs), h = c(hPs), calcVol = c(volEstoniaPs)), Slovenia=data.frame(land = "Slovenia", dbh = c(dbhPs), h = c(hPs), calcVol = c(volSloveniaPs)))` and so on. Then you'd have the separate countries stored cleanly and could combine them using `mydf <- do.call(rbind, myList)`. See gregor's answer to [this post](https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) for more tips on working with lists of data.frames. – lmo Oct 10 '17 at 12:24
  • 1
    Can you `dput` the data you used as input? You can probably `group_by` country and calculate the volumes, it would be much more effective. – csgroen Oct 10 '17 at 14:26

0 Answers0