null_void
null_void

Reputation: 1

I cannot bind rows in R

I'm just a beginner in R and I'm having trouble in a capstone project on the google analytics data certification. I have to analyze data from a fictional company from the last 12 months (I've chosen June22 to May 23), and after creating dataframes for each months, I'm trying to bind_rows to create a single database for the whole year. But I'm encountering this issue:

> rides_last_year <- bind_rows(june_2022, july_2022, august_2022, 
+ september_2022, october_2022, november_2022, december_2022, january_2023, february_2023, march_2023, 
+ april_2023, may_2023)
Error in `bind_rows()`:
! Can't combine `..1$started_at` <datetime<UTC>> and `..2$started_at` <character>.
Run `rlang::last_trace()` to see where the error occurred.

If you need more info I'll gladly provide it.

PS: june_2022 and so on are the dataframes created for this project.

Got no idea to solve it, right now, do I have to change something from my data?

Upvotes: 0

Views: 45

Answers (1)

AndS.
AndS.

Reputation: 8120

If it was me, I would put everything in a list, use map_dfr to cast everything to the same type and simultaneously bind the rows, then type convert on the back end.

library(tidyverse)

list(june_2022, july_2022, august_2022, september_2022, october_2022, 
     november_2022, december_2022, january_2023, february_2023, 
     march_2023, april_2023, may_2023) |>
  map_dfr(~mutate(across(everything(), as.character))) |>
  type_convert()

If you know that started_at is the only problem variable, you could just cast that one variable and save yourself some time. I imagine that you'll probably have problems with ended_at as well.

Upvotes: 0

Related Questions