When your write.csv won’t write

Today I learned that:

  • A column in a data frame can actually be a list even if it looks nice when you peek at it with head() and tail()
  • If you take this data frame and try to write it to a csv file using write.csv, you’re probably going to get an error like this in mean red letters:

Error in .External2(C_writetable, x, file, nrow(x), p, rnames, sep, eol, :
unimplemented type ‘list’ in ‘EncodeElement’

To avoid this, you should first check the data type for each column:

sapply(df, class)

Use unlist() or similar to fix the offending columns. This should fix the problem and write.csv() will happily dump your data as requested.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s