1

I receive the error

Error: times can't be missing. Location 1 is missing. In addition: Warning message: In nrow * ncol : NAs produced by integer overflow

when calling:

data_indicator <- data_pivoted %>% select(ID, var) %>%
  mutate(val = TRUE) %>% 
  pivot_wider(id_col=ID, names_from = var, values_from = val, values_fill = FALSE)

data_pivoted is 8292624 obs. of 3 variables

summary(data_pivoted)

       ID             var                 val         
 Min.   :     1   Length:8292624     Min.   :  -743   
 1st Qu.: 98342   Class :character   1st Qu.:     6   
 Median :197353   Mode  :character   Median :    10   
 Mean   :196777                      Mean   :    58   
 3rd Qu.:295272                      3rd Qu.:    18   
 Max.   :392696                      Max.   :330318   
                                     NA's   :8000821  

Any suggestion what is wrong here?

> dput(head(data_pivoted))
structure(list(ID = c(1L, 1L, 1L, 1L, 1L, 1L), var = c("239", 
"200", "229", "100", "101", "102"), val = c(5, NA, NA, NA, NA, 
NA)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))
Chris
  • 156
  • 1
  • 1
  • 9
  • Please share a reproducible sample of your data with `dput(head(data))` so that others can use it to help you. – Anoushiravan R Apr 01 '22 at 14:00
  • Your example runs fine for me? Did you restart R? Which packages have you loaded? Try only loading the required tidyverse packages or explicitely call the package via e.g. dplyr::select. – deschen Apr 01 '22 at 14:21
  • Your example works fine for me as well. – jpiversen Apr 01 '22 at 14:21
  • 3
    Chris, one challenge when asking for help is providing not-too-big sample data so that we can reproduce the issue. The key is "reproduce", since the sample data you provided isn't failing. If you need to come up with a few more rows to produce the error, that's fine, but please ensure it does produce it before saving your question-edit. My guess is that there's some non-uniqueness in your keys and something perhaps `NA` elsewhere. – r2evans Apr 01 '22 at 14:25
  • I just saw this same problem. Fixed it. The size of objects in the global environment increased beyond the memory of the system during the pivot. Watch your meter and see if that is happening. – Harlan Nelson Nov 19 '22 at 21:28

1 Answers1

3

I got the same error. The dataset I was using was very large, so I used split and pivot_wider in a map_dffunction.

Using your example

data_pivoted %>% 
select(ID, var) %>%
mutate(val = TRUE) %>%
split(.$ID) %>%
map_df(~ pivot_wider(.x,
                   names_from = var,
                   values_from =  val,
                   values_fill = FALSE))
lacapary
  • 31
  • 5
  • As it's currently written, your answer seems not very clear. Could you provide the exact code that you used in order to solve the problem? Ideally, you may also show an example of what the data looked like before and after. – benimwolfspelz May 24 '22 at 10:32