When I ran the code from the tutorial, they were using a depreciated function as.tibble() in tidyverse that threw errors. I changed this to as_tibble() and ran the rest of the code through the lines in your screenshot without any errors. Did you view your velocity.all dataframe before trying to filter it? If you had NULL values due to the tibble error that may have been your issue.
require(xtractomatic)
require(tidyverse)
require(oce)
require(lubridate)
require(gganimate)
require(sf)
getInfo("qsux101day")
getInfo("qsuy101day")
# set spatial extent
lon = c(25,65)
lat = c(-35,10)
## set temporal extent
time = c("2006-01-01", "2006-12-31")
wind_x = xtracto_3D(dtype = "qsux101day",
xpos = lon,
ypos = lat,
tpos = time)
wind_y = xtracto_3D(dtype = "qsuy101day",
xpos = lon,
ypos = lat,
tpos = time)
## extract location and time bounds as vector
longitude = wind_x$longitude
latitude = wind_x$latitude
time = wind_x$time%>%as.Date()
## extract u and v as array
# eastward velocity (zonal)
u = wind_x$data
# northward velocity (meridional)
v = wind_y$data
# calculate wind velocity
velocity = sqrt(u^2 + v^2)
n.lon = length(longitude)
n.lat = length(latitude)+1
velocity.all = NULL
for (i in 1:length(time)){
velocity.df = data.frame(longitude, velocity[,,i] %>% as.data.frame()) %>%
gather(key = "key" , value = "velocity", 2:n.lat) %>%
mutate(latitude = rep(latitude, each = n.lon), date = time[i]) %>%
select(date,longitude, latitude, velocity)%>%
as_tibble()
velocity.all = velocity.all %>% bind_rows(velocity.df)
}
velocity.month = velocity.all %>%
filter(between(longitude,38,55)) %>%
filter(between(latitude,-15,-7)) %>%
mutate(day = yday(date) %>% as.integer(), week = week(date)%>% as.integer(),
month = month(date)%>% as.integer())%>%
group_by(longitude, latitude, month) %>%
summarise(velocity = mean(velocity, na.rm = TRUE))