Hello, I am trying to learn how to create a simulated dataset of a forest stand: I must simulate 10 stands, for each of the stands I have been creating a random number of trees. For each tree I should create a random diameter. The problem I have is that I cannot use a matrix because the length of the three items is different. I was trying with list but I have no clue on how to make a dataset out of them... tried "merge".... Anyone has some clever suggestion? THANK you !! Giovanna Giovanna Ottaviani Aalmo Stipendiat/Ph.D. Student ------------------------------------------- Norsk institutt for skog og landskap Pb 115, NO-1431 Ås T (+47) 64 94 9094 M(+47) 980 30 422 F(+47) 64 94 90 80 ------------------------------------------- www.skogoglandskap.no<http://www.skogoglandskap.no/> ------------------------------------------- [[alternative HTML version deleted]]
Is this a homework problem? (We don't do homework here). What is missing from your query is any specification of what you mean by "random," which, by itself, is meaningless. It also might be the case that the trees within each stand are correlated in some way -- perhaps they should to be more similar in diameter within a stand than between. So I think your first task is to think more carefully about **what** you want to do and how to specify it precisely and completely before worrying about **how** to do it.. Cheers, Bert On Sat, Feb 2, 2013 at 12:10 PM, Giovanna Ottaviani <GIO at skogoglandskap.no> wrote:> Hello, > I am trying to learn how to create a simulated dataset of a forest stand: > I must simulate 10 stands, for each of the stands I have been creating a random number of trees. For each tree I should create a random diameter. > The problem I have is that I cannot use a matrix because the length of the three items is different. I was trying with list but I have no clue on how to make a dataset out of them... tried "merge".... > Anyone has some clever suggestion? > THANK you !! > Giovanna > > > Giovanna Ottaviani Aalmo > Stipendiat/Ph.D. Student > ------------------------------------------- > Norsk institutt for skog og landskap > Pb 115, NO-1431 ?s > T (+47) 64 94 9094 > M(+47) 980 30 422 > F(+47) 64 94 90 80 > ------------------------------------------- > www.skogoglandskap.no<http://www.skogoglandskap.no/> > ------------------------------------------- > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Hello, Once you formulate the problem properly, it's not hard to solve it in R. Bert's questions should be answered before continuing. I'll make two assumptions, not present in your post. All diameters are assumed independent and to follow the same uniform distribution. (iid scenario; the two assumptions you have to decide about.) With these in mind, you can get some inspiration from the following code. It produces 10 vectors of a random numbers of trees of random diameters. min.diam <- 1 # trees' diameters max.diam <- 2 # max.trees <- 10 # trees per stand lapply(1:10, function(i) runif(sample(max.trees, 1), min.diam, max.diam)) Hope this helps, Rui Barradas Em 02-02-2013 20:10, Giovanna Ottaviani escreveu:> Hello, > I am trying to learn how to create a simulated dataset of a forest stand: > I must simulate 10 stands, for each of the stands I have been creating a random number of trees. For each tree I should create a random diameter. > The problem I have is that I cannot use a matrix because the length of the three items is different. I was trying with list but I have no clue on how to make a dataset out of them... tried "merge".... > Anyone has some clever suggestion? > THANK you !! > Giovanna > > > Giovanna Ottaviani Aalmo > Stipendiat/Ph.D. Student > ------------------------------------------- > Norsk institutt for skog og landskap > Pb 115, NO-1431 ?s > T (+47) 64 94 9094 > M(+47) 980 30 422 > F(+47) 64 94 90 80 > ------------------------------------------- > www.skogoglandskap.no<http://www.skogoglandskap.no/> > ------------------------------------------- > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >