-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4.Merge_alldata.Rmd
More file actions
79 lines (60 loc) · 2.56 KB
/
4.Merge_alldata.Rmd
File metadata and controls
79 lines (60 loc) · 2.56 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: "Merge_data"
author: "Camila Calderon"
date: "2024-07-22"
output: html_document
---
## Load libraries
```{r setup}
library(lubridate)
library(dplyr)
library(ggplot2)
```
## Load data
```{r load data}
# 2016
load(file="~/ownCloud/PhDLife/P.hastatus/Thesis/paper1/BiologyLetters/data/Phyllostomus2016_resample_clean.RData")
# 2022
load(file="~/ownCloud/PhDLife/P.hastatus/Thesis/paper1/BiologyLetters/data/BatsBocas_nooutliers.RData")
# 2023
load(file="~/ownCloud/PhDLife/P.hastatus/Thesis/paper1/BiologyLetters/data/PhasBocas_2023_clean.RData")
# check column names
names(phasprocessed)
names(batsdf_new)
names(batsdf2023_clean)
# add column of altitude so is equal to the other two data frames
batsdf2023_clean$height_above_msl <- batsdf2023_clean$height_above_ellipsoid
# add columns to date and time columns to data frame in 2022 and 2023
batsdf_new$time <- format(batsdf_new$timestamps, format = "%H:%M:%S")
batsdf_new <- batsdf_new[order(batsdf_new$tag_local_identifier, batsdf_new$timestamps),]
batsdf2023_clean$time <- format(batsdf2023_clean$timestamps, format = "%H:%M:%S")
batsdf2023_clean <- batsdf2023_clean[order(batsdf2023_clean$tag_local_identifier, batsdf2023_clean$timestamps),]
```
## Make all three data frames match
```{r, results=FALSE}
# make columns to match all three data frames
cols <- intersect(colnames(batsdf_new), colnames(phasprocessed))
cols <- intersect(cols, colnames(batsdf2023_clean))
# merge data frame by row
allbats_Bocas <- rbind(phasprocessed[,cols], batsdf_new[,cols], batsdf2023_clean[,cols])
names(allbats_Bocas)
# add month column
allbats_Bocas$month <- month.abb[month(allbats_Bocas$timestamp)]
# remove data with speeds larger than 15
indx <- which(allbats_Bocas$ground_speed>16)
allbats_Bocas <- allbats_Bocas[-indx,]
hist(allbats_Bocas$ground_speed)
unique(allbats_Bocas$ID_batday)
#add date
allbats_Bocas$date <- date(allbats_Bocas$timestamp)
# add year cave to the data frame
allbats_Bocas$year <- lubridate::year(ymd(allbats_Bocas$date))
allbats_Bocas$year_cave <- paste(allbats_Bocas$year, allbats_Bocas$cave, sep="_")
allbats_Bocas$year_month<- paste(allbats_Bocas$year, allbats_Bocas$month, sep="_")
allbats_Bocas$year_cave[which(allbats_Bocas$year_month=="2022_Feb")] <- "2022_lagruta_Feb"
allbats_Bocas$year_cave[which(allbats_Bocas$year_month=="2022_Jan")] <- "2022_lagruta_Feb"
allbats_Bocas$year_cave[which(allbats_Bocas$year_cave=="2022_lagruta")] <- "2022_lagruta_Mar"
unique(allbats_Bocas$year_cave)
# save
save(allbats_Bocas, file="~/ownCloud/PhDLife/P.hastatus/Thesis/paper1/BiologyLetters/data/allPhastBocas_merged.RData")
```