Vector Type change

I am using the pivot_wider command to reshape my data, and I noticed all variables in my data set ( more than 100 columns) changed to "list" data type. They were integers, doubles and characters before I applied the pivot. Does anyone know how to prevent or resolve this?

This usually happens when you have more than one value per column and row identifier, if you don't pass a summarizing function you get a list with all values.

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

library(tidyverse)
data.frame(
  stringsAsFactors = FALSE,
       KEY_PATIENT = c("uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0/NumbVisitRepeat[1]",
                       "uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0/NumbVisitRepeat[2]",
                       "uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0/NumbVisitRepeat[3]",
                       "uuid:0047aac7-f803-4b76-beea-9f84cf81506d/NumbVisitRepeat[1]",
                       "uuid:0047aac7-f803-4b76-beea-9f84cf81506d/NumbVisitRepeat[2]",
                       "uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0/NumbVisitRepeat[1]",
                       "uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0/NumbVisitRepeat[2]",
                       "uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0/NumbVisitRepeat[3]",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[1]",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[2]",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[3]",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[4]",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[5]",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[6]",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[7]"),
   KEY_visitNumber = c(1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 4, 5, 6, 7),
         VisitDate = c("30/04/2019","6/10/2019",
                       "1/12/2019","15/11/2019","28/11/2019","24/01/2019",
                       "1/2/2019","8/2/2019","12/1/2019","10/2/2019","23/03/2019",
                       "15/05/2019","15/06/2019","27/07/2019","3/8/2019"),
     HealthInsurYN = c("no","yes","yes","no","no",
                       "no","no","no","yes","yes","no","no","yes","yes",
                       "yes"),
       BPMeasureYN = c("yes","yes","yes","yes",
                       "yes","yes","yes","yes","yes","yes","yes","yes",
                       "yes","yes","yes"),
               SBP = c(150,147,137,180,160,180,
                       146,130,130,150,150,150,130,160,140),
          BMIDocYN = c("no","no","no","no","no",
                       "no","no","no","no","no","no","no","no","no","no"),
      AbdCirmDocYN = c("no","no","no","no","no",
                       "no","no","no","no","no","no","no","no","no","no"),
        KEY_PARENT = c("uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0","uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0",
                       "uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0",
                       "uuid:0047aac7-f803-4b76-beea-9f84cf81506d",
                       "uuid:0047aac7-f803-4b76-beea-9f84cf81506d",
                       "uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0","uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0",
                       "uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a","uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a")
)
#>                                                     KEY_PATIENT KEY_visitNumber
#> 1  uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0/NumbVisitRepeat[1]               1
#> 2  uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0/NumbVisitRepeat[2]               2
#> 3  uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0/NumbVisitRepeat[3]               3
#> 4  uuid:0047aac7-f803-4b76-beea-9f84cf81506d/NumbVisitRepeat[1]               1
#> 5  uuid:0047aac7-f803-4b76-beea-9f84cf81506d/NumbVisitRepeat[2]               2
#> 6  uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0/NumbVisitRepeat[1]               1
#> 7  uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0/NumbVisitRepeat[2]               2
#> 8  uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0/NumbVisitRepeat[3]               3
#> 9  uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[1]               1
#> 10 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[2]               2
#> 11 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[3]               3
#> 12 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[4]               4
#> 13 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[5]               5
#> 14 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[6]               6
#> 15 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a/NumbVisitRepeat[7]               7
#>     VisitDate HealthInsurYN BPMeasureYN SBP BMIDocYN AbdCirmDocYN
#> 1  30/04/2019            no         yes 150       no           no
#> 2   6/10/2019           yes         yes 147       no           no
#> 3   1/12/2019           yes         yes 137       no           no
#> 4  15/11/2019            no         yes 180       no           no
#> 5  28/11/2019            no         yes 160       no           no
#> 6  24/01/2019            no         yes 180       no           no
#> 7    1/2/2019            no         yes 146       no           no
#> 8    8/2/2019            no         yes 130       no           no
#> 9   12/1/2019           yes         yes 130       no           no
#> 10  10/2/2019           yes         yes 150       no           no
#> 11 23/03/2019            no         yes 150       no           no
#> 12 15/05/2019            no         yes 150       no           no
#> 13 15/06/2019           yes         yes 130       no           no
#> 14 27/07/2019           yes         yes 160       no           no
#> 15   3/8/2019           yes         yes 140       no           no
#>                                   KEY_PARENT
#> 1  uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0
#> 2  uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0
#> 3  uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0
#> 4  uuid:0047aac7-f803-4b76-beea-9f84cf81506d
#> 5  uuid:0047aac7-f803-4b76-beea-9f84cf81506d
#> 6  uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0
#> 7  uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0
#> 8  uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0
#> 9  uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a
#> 10 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a
#> 11 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a
#> 12 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a
#> 13 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a
#> 14 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a
#> 15 uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a

cli_visits_wider <- cli_visits%>% 
  arrange(KEY_visitNumber) %>% # 
  pivot_wider(
    id_cols = KEY_PARENT,
    names_from = KEY_visitNumber,
    names_glue = "visit-{KEY_visitNumber}-{.value}",
    values_from = VisitDate:AbdCirmDocYN)
#> Error in eval(lhs, parent, parent): object 'cli_visits' not found

Created on 2021-03-14 by the reprex package (v1.0.0)

Thank you andresrcs, here is a reprex above

Your example does not show any list type variables in the output.
p.s. this is after accounting for the need to assign the data.frame you shared with the cli_visits name

library(tidyverse)
cli_visit <- data.frame(
  stringsAsFactors = FALSE,
         VisitDate = c("30/04/2019","6/10/2019",
                       "1/12/2019","15/11/2019","28/11/2019","24/01/2019",
                       "1/2/2019","8/2/2019","12/1/2019","10/2/2019","23/03/2019",
                       "15/05/2019","15/06/2019","27/07/2019","3/8/2019",
                       "24/08/2019","19/10/2019","17/09/2019","15/10/2019",
                       "29/07/2019","31/07/2019","14/08/2019","10/8/2019",
                       "14/08/2019","8/2/2019"),
     HealthInsurYN = c("no","yes","yes","no","no",
                       "no","no","no","yes","yes","no","no","yes","yes",
                       "yes","yes","yes","no","no","no","no","no","no",
                       "no","no"),
       BPMeasureYN = c("yes","yes","yes","yes",
                       "yes","yes","yes","yes","yes","yes","yes","yes",
                       "yes","yes","yes","yes","yes","yes","yes","yes","yes",
                       "yes","yes","no","yes"),
       WeightValue = c(NA,NA,NA,NA,NA,77,76,
                       75.5,98.4,97.5,99.2,99.5,99,98.3,98,97.8,98.6,95,
                       93,95,95,NA,NA,NA,60),
        WeightUnit = c(NA,NA,NA,NA,NA,"kg","kg",
                       "kg","kg","kg","kg","kg","kg","kg","kg","kg",
                       "kg","kg","kg","kg","kg",NA,NA,NA,"kg"),
       HeightDocYN = c("no","no","no","no","no",
                       "no","no","no","no","no","no","no","no","no","no",
                       "no","no","no","no","no","no","no","no","no",
                       "no"),
        HeightUnit = c(NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA),
               SBP = c(150,147,137,180,160,180,
                       146,130,130,150,150,150,130,160,140,130,150,160,
                       144,140,178,149,170,NA,151),
          BMIDocYN = c("no","no","no","no","no",
                       "no","no","no","no","no","no","no","no","no","no",
                       "no","no","no","no","no","no","no","no","no",
                       "no"),
      AbdCirmDocYN = c("no","no","no","no","no",
                       "no","no","no","no","no","no","no","no","no","no",
                       "no","no","no","no","no","no","no","no","no",
                       "no"),
        KEY_PARENT = c("uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0","uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0",
                       "uuid:00226e78-ab5f-4c0b-b0a3-6b745e3fbca0",
                       "uuid:0047aac7-f803-4b76-beea-9f84cf81506d",
                       "uuid:0047aac7-f803-4b76-beea-9f84cf81506d",
                       "uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0","uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0",
                       "uuid:0062433f-3e12-41dc-a13e-e63e121fe4a0",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a","uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a","uuid:0063cbfc-ce81-4b2a-b3b9-8d3bd8162a8a",
                       "uuid:0088b9f6-6305-4a87-bccb-2b2b66f91079",
                       "uuid:0088b9f6-6305-4a87-bccb-2b2b66f91079",
                       "uuid:00948da0-b3ca-4829-9f96-14f337c88b15","uuid:00948da0-b3ca-4829-9f96-14f337c88b15",
                       "uuid:00948da0-b3ca-4829-9f96-14f337c88b15",
                       "uuid:00b1510b-77be-4aff-b820-58614278e035",
                       "uuid:00b1510b-77be-4aff-b820-58614278e035",
                       "uuid:00b7756b-b6f1-4bc1-8a64-fd8c367c417b")
)
cli_visits_wider <- cli_visits%>% 
  arrange(KEY_visitNumber) %>% # 
  pivot_wider(
    id_cols = KEY_PARENT,
    names_from = KEY_visitNumber,
    names_glue = "visit-{KEY_visitNumber}-{.value}",
    values_from = VisitDate:AbdCirmDocYN)
#> Error in eval(lhs, parent, parent): object 'cli_visits' not found

Created on 2021-03-14 by the reprex package (v1.0.0)

I apologize. I was trying to provide as small a data sample as possible. This updated reprex shows the list error

Your new sample data contains no KEY_visitNumber column thus your code doesn't run. Can you check on that and make sure your code is reproducible before you post?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.