-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomTreesTax.R
42 lines (33 loc) · 1.09 KB
/
RandomTreesTax.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# install.packages("readxl")
library(readxl)
# Load the Excel file
data = read_excel("C:/Users/admin/Desktop/Uploads GitHub/Oaks_Species_Section/OakSection.xlsx")
# Group the Oak (Quercus) species by section
sections = split(data$Quercus, data$Sektion)
# Function to sample three species from each section
sample_species = function(section) {
sample(section, 3, replace = FALSE)
}
# Function to generate random species for each section
generate_random_species = function() {
# Applying the function to each section
random_species = lapply(sections, sample_species)
# Print the random species for each section
for (section_name in names(random_species)) {
cat("Section:", section_name, "\n")
cat("Species:", random_species[[section_name]], "\n\n")
}
}
# Function to prompt user for continuation
continue_prompt = function() {
cat("Do you want to generate random species again? (yes/no): ")
response = readline()
return(tolower(response) == "yes")
}
# Generate random species until user decides to stop
repeat {
generate_random_species()
if (!continue_prompt()) {
break
}
}