Circadian classification

r
biologging
sula
Y2022

Create a column with the classification day or night

Author

Miriam Lerma

Published

December 4, 2022

Intro

This post is to create a column day or night.

Data

For the exercises, test data is from masked boobies.
To access the data you have to install the package sula: devtools::install_github(“MiriamLL/sula”)

#devtools::install_github("MiriamLL/sula")
library(sula)
GPS01<-(GPS_01)

Transform time and date

library(dplyr)

Identify column with time date data

GPS01$dt <- as.POSIXct(strptime(GPS01$tStamp, "%Y-%m-%d %H:%M:%S"))

Extract hours

Once is in time and date format, you can extract just the hours

GPS01$hour <- as.numeric(substr(GPS01$dt, 12, 13))

Classify day and night

Create a classification base on the time of sunset and sunrise.

GPS01<-GPS01 %>%
 mutate(
    day_night = case_when(
      hour > 20 |  hour < 6 ~ "night",
      TRUE  ~ "day"
    ))

Quantify proportions

library(tidyverse)

Now you can quantify how much your animals were out at night

GPS01 %>%
  group_by(day_night)%>%
  count()%>%
  pivot_wider(names_from = day_night, values_from = n)

I hope this might help you

Further reads

Classify activities at night in penguins