Hi! no reprex yet cause i don't have any code.. just seeking help in understand witch function i should use...
I have this simple DB with 3 columns: Tree Species, Diameter minimum and Diameter max.
I want to create a dataset (usually i use expand.grid) that include 100 numbers (for specie) between Dmin and Dmax (equally spaced wuold be nice) in a new column Dpoints (considering that every species have his own Dmin and Dmax)
i think i need a nested approach?
Thanks for your time!
Michel
Here is one method. I only put in 4 points so the result can be displayed.
library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.1.2
DF <- data.frame(Tree=c("A","B"),
Dmin=c(1,25),
Dmax=c(10,60))
DF
#> Tree Dmin Dmax
#> 1 A 1 10
#> 2 B 25 60
DF2 <- DF |> group_by(Tree) |>
summarize(Dpoints=seq(Dmin,Dmax,length.out=4))
#> `summarise()` has grouped output by 'Tree'. You can override using the `.groups`
#> argument.
DF2
#> # A tibble: 8 x 2
#> # Groups: Tree [2]
#> Tree Dpoints
#> <chr> <dbl>
#> 1 A 1
#> 2 A 4
#> 3 A 7
#> 4 A 10
#> 5 B 25
#> 6 B 36.7
#> 7 B 48.3
#> 8 B 60
#If you want to append DF2 to the original data
DF <- inner_join(DF,DF2,by="Tree")