Hi there,
This code worked on Friday... I think my computer updated over the weekend, and now the code throws an error. Can't understand why, any help is much appreciated.
# recreate first 5 rows of the data (full df is ~142000 rows)
lis <- structure(list(datetime = structure(c(1372662000, 1372662900,
1372663800, 1372664700, 1372665600), class = c("POSIXct", "POSIXt"
), tzone = ""), year = c(2013, 2013, 2013, 2013, 2013), month = structure(c(7L,
7L, 7L, 7L, 7L), .Label = c("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November",
"December"), class = "factor"), value = c(-95, -132, -196, -234,
-236)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"
))
# compute daily mean flow and plot:
lis %>%
mutate(date = as.Date(datetime)) %>% # get rid of hms
group_by(date) %>%
mutate(meanflow = mean(value)) %>%
ungroup() %>%
filter(!duplicated(date)) %>% # this is where the error happens
ggplot() +
geom_line(aes(x = date, y = meanflow))
The error I get is: Error in duplicated.default(date) : duplicated() applies only to vectors
Wrapping date
in as.vector()
does not help; lubridate
's ymd
function fills the date column with NAs (although that's probably just a formatting issue I could troubleshoot).
I realize that naming something date
is a bad idea... but I've tried with different names and get the same error.
Session info:
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2.2 lubridate_1.7.4 DWR_0.0.0.9000 ybp_0.1.0 fishtrackr_0.1.0 forcats_0.3.0 stringr_1.3.1 dplyr_0.7.6
[9] purrr_0.2.5 readr_1.1.1 tidyr_0.8.1 tibble_1.4.2 ggplot2_3.0.0 tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 compiler_3.5.1 cellranger_1.1.0 pillar_1.3.0 plyr_1.8.4 bindr_0.1.1 tools_3.5.1 jsonlite_1.5
[9] gtable_0.2.0 nlme_3.1-137 lattice_0.20-35 pkgconfig_2.0.1 rlang_0.2.1 cli_1.0.0 rstudioapi_0.7 yaml_2.2.0
[17] haven_1.1.2 withr_2.1.2 xml2_1.2.0 httr_1.3.1 hms_0.4.2 grid_3.5.1 tidyselect_0.2.4 glue_1.3.0
[25] R6_2.2.2 readxl_1.1.0 modelr_0.1.2 magrittr_1.5 backports_1.1.2 scales_0.5.0 rvest_0.3.2 assertthat_0.2.0
[33] colorspace_1.3-2 stringi_1.2.4 lazyeval_0.2.1 munsell_0.5.0 broom_0.5.0 crayon_1.3.4
Any ideas?