0

I am currently trying to export a panel dataset in R to a CSV file. When exporting I receive the following error message in R:

Error in `is.data.frame()`:
! Can't recycle `value` (size 6) to size 4.
Backtrace:
  1. utils::write.csv(merge_long, "Merge_Long.csv")
  5. utils::write.table(...)
 14. tibble:::`[<-.tbl_df`(`*tmp*`, needconv, value = `<named list>`)

After the supposed export, I receive an empty CSV file in my Explorer.

I once displayed which data object my panel dataset "Merge-Long" has. Unfortunately, I no longer know what I can/should do.

> class(merge_long)
[1] "panel_data" "grouped_df" "tbl_df"     "tbl"        "data.frame"
5
  • a couple of questions: 1. can you create a new df, head_df, by doing head_df <- head(merge_long), and check if it fails for head_df too? If yes, run dput() on it, and edit your question to add the output to it. 2. Try using readr::write_csv() instead Commented Nov 6, 2023 at 13:23
  • Hi Mark, readr::write_csv() works! Many thanks for your help! Commented Nov 6, 2023 at 13:52
  • I'm guessing what happened was, your dataframe contained list columns, or perhaps columns which themselves contained dataframes, and the base R write.csv() didn't like that Commented Nov 6, 2023 at 14:55
  • though it could be that your data is of the class panel_data, and/or is a grouped df Commented Nov 6, 2023 at 14:56
  • hard to say without experimenting with the data Commented Nov 6, 2023 at 14:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.