Not sure which update caused my code to begin crashing, but rowSums doesn't seem to work anymore when the first column is dttm.
I have a tibble of timeseries data. I want to sum across all the numeric columns where the number of numeric columns varies in each loop. My original code looked like this:
Now I get an error that says:
Error in [<-:
! Assigned data values must be compatible with existing data.
??? Error occurred for column DateTime.
Caused by error in vec_assign():
! Can't convert to <datetime>.
My solution was to drop the DateTime column and sum across all the rows and then cbind the columns back together, which is not very elegant.
Silly I know, but was curious as to why I couldn't get rowSums to work without dropping the "DateTime" column. I even tried various versions of the mutate statement that specifically calls out "DateTime" with a setdiff
Well this is not possible: in a tibble (or data frame), the columns must all have the same number of rows. If I try running this example code, I get the expected error:
library(tidyverse)
set.seed(1)
sub_data <- tibble(
DateTime = ymd_hms("2010-08-03 00:50:50", "2012-08-03 15:50:50"),
other = rnorm(4)
)
#> Error in `tibble()`:
#> ! Tibble columns must have compatible sizes.
#> • Size 2: Existing data.
#> • Size 4: Column `other`.
#> ℹ Only values of size one are recycled.
Can you create a reproducible example that gives this error?
If your data is not confidential, maybe you can share the result of dput(head(sub_data)) so we can work with your actual data.
Upon further investigation, it seem you are right and the error is a pre-processing one. There is an NA in the DateTime field and it couldn't coerce the datetime object to a double.
Thanks for looking into this though. Much appreciated!