-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWCVP_Lifeform_Datapull.R
43 lines (30 loc) · 1.13 KB
/
WCVP_Lifeform_Datapull.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
43
# Set the working directory
setwd("H:/Plant Records/Collections Development/Focus Regions/Global_WCVP")
# Read the pipe-separated file
wcvp_data <- read.csv("wcvp_names.csv", sep = "|")
# Check the structure of the data
str(wcvp_data)
# Print column names
print(colnames(wcvp_data))
# View the first few rows
head(wcvp_data)
# Access the lifeform_description column
lifeform_values <- wcvp_data$lifeform_description
# Print the first few values
print(head(lifeform_values))
# Get unique lifeform descriptions
unique_lifeforms <- unique(lifeform_values)
# Print unique values
print(unique_lifeforms)
# Count unique values
print(length(unique_lifeforms))
# Create a frequency table
lifeform_freq <- table(lifeform_values)
# Sort the frequency table in descending order
lifeform_freq_sorted <- sort(lifeform_freq, decreasing = TRUE)
# Print sorted frequency table
print(lifeform_freq_sorted)
# Save frequency table to CSV
write.csv(data.frame(lifeform = names(lifeform_freq_sorted),
frequency = as.vector(lifeform_freq_sorted)),
"lifeform_frequencies.csv", row.names = FALSE)