-
Notifications
You must be signed in to change notification settings - Fork 6
/
multiyear_functions.R
52 lines (34 loc) · 1.37 KB
/
multiyear_functions.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
44
45
46
47
48
49
50
# Functions for handling multi-year datasets. These functions assume that ALL
# YEARS have been compared with the same database using the same classifier to
# avoid inter-year differences in taxonomic assignment.
# Last modified by KDyson 09/15/2023
## ----- Data manip. funs. | compile ---------------------------
# Compiles multiple years of data into one table. Year column is created when
# merging. Tables should otherwise have the same columns prior to merging.
# Double check that all columns with the same name have the same data and data
# type.
# years should be a list of all years
# ... should be the dataframes for all years
# These MUST be in the same order otherwise you'll mess up your data.
# table1 <- data.frame('species' = 1:10)
# table2 <- data.frame('species' = 15:20)
# years <- c(2002,3003)
# multiyear_merge(years, table1,table2)
multiyear_merge <- function(years, ...){
# rbind the different tables to one another
output <- rbind(...)
# count rows of each table input
i = 1
n <- ...length()
length_list <- rep(0,n)
for(i in 1:n) {
length_list[[i]] <- nrow(...elt(i))
print(...elt(i))
}
print(...length())
print(length_list)
# add the year column
output$year <- rep(years, length_list)
return(output)
}
## ----- Data manip. funs. | trim ---------------------------