Basic Data Structures and Manipulations

Characters and Vectors

Create a Single Character Vector

bug <- "ladybug"

Create a Character Vector

bugs <- c("firefly", "cicada", "cricket", "bee", "grasshopper")

Numerics and Vectors

Create a Single Numeric Vector

numeric <- 1

Create a Numeric Vector

numeric_vector <- c(2, 4, 6, 8, 10)

Create a List

bugs_list <- as.list(bugs)

Boolean

# Is 5 greater than 7? Store boolean value as "ans1"
ans1 <- 5 > 7

# Is 2 equal to 2? Store boolean value as "ans2"
ans2 <- 2 == 2

Reformatting Date/Time

# Install required library
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
# Create a value for the current date/time in hr:min UTC
current_hm <- "2026-09-27 12:45"

# Reformat the current time to be in hr:min:s UTC and store as new value
current_hms <- ymd_hms(current_hm, truncated = 1)

# Confirm that reformatting was successful in new value
current_hms
## [1] "2026-09-27 12:45:00 UTC"

Basic Data Structuring

Create a Data Frame

# Create data frame
birds <- data.frame(
  Bird = c("Cedar Waxwing", "American Robin", "Palm Warbler", "Gray Catbird", "Yellow-Throated Warbler"),
  Banded_Day = c("2026-09-27", "2026-09-27", "2026-09-27", "2026-09-27", "2026-09-27"),
  Time_Banded = c("08:00", "09:00", "08:00", "11:00", "14:00")
)

# View data frame
birds
##                      Bird Banded_Day Time_Banded
## 1           Cedar Waxwing 2026-09-27       08:00
## 2          American Robin 2026-09-27       09:00
## 3            Palm Warbler 2026-09-27       08:00
## 4            Gray Catbird 2026-09-27       11:00
## 5 Yellow-Throated Warbler 2026-09-27       14:00

Create a Tibble

# Installed required library
library(tibble)

# Create a tibble from the "birds" data frame
birds_tibble <- as_tibble(birds)

# View the tibble
## Whole data frame will be shown since the tibble is less than 10 lines long
birds_tibble
## # A tibble: 5 × 3
##   Bird                    Banded_Day Time_Banded
##   <chr>                   <chr>      <chr>      
## 1 Cedar Waxwing           2026-09-27 08:00      
## 2 American Robin          2026-09-27 09:00      
## 3 Palm Warbler            2026-09-27 08:00      
## 4 Gray Catbird            2026-09-27 11:00      
## 5 Yellow-Throated Warbler 2026-09-27 14:00

Create an Array

# Arrange a sequence of numbers 1-24 with 4 rows, 2 columns, and 3 layers
numberArray <- array(1:24, dim = c(4, 2, 3))

# View the array
numberArray
## , , 1
## 
##      [,1] [,2]
## [1,]    1    5
## [2,]    2    6
## [3,]    3    7
## [4,]    4    8
## 
## , , 2
## 
##      [,1] [,2]
## [1,]    9   13
## [2,]   10   14
## [3,]   11   15
## [4,]   12   16
## 
## , , 3
## 
##      [,1] [,2]
## [1,]   17   21
## [2,]   18   22
## [3,]   19   23
## [4,]   20   24