将R中的数据帧输出到.csv [英] Outputting a Dataframe in R to a .csv

查看:92
本文介绍了将R中的数据帧输出到.csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图基于R中的数据帧编写.csv文件,但由于某些原因,我一直收到以下错误消息:

So I'm trying to write a .csv file based on a data frame in R, but for some reason I keep getting the following error:

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

这是traceback()提供的:

This is what traceback() is giving:

5: write.table(df, file = "df.csv", col.names = NA, 
       sep = ",", dec = ".", qmethod = "double")
4: eval(expr, envir, enclos)
3: eval(expr, p)
2: eval.parent(Call)
1: write.csv(df, file = "df.csv")

有解决方案吗?

推荐答案

您的一列属于列表类型,因此data.frame不再是二维的,并且不能导出到2d的csv文件.

One of your columns is of type list, so the data.frame is no longer 2-dimensional and can't be exported to a 2d csv-file.

如果您仍然希望将列表存储在结果输出中,则可以先将其转换为JSON.因此,它成为字符"类型的列,可以很容易地作为一个列导出到csv.

If you still want to store the list in the resulting output, you might transform it to JSON first. So it becomes an column of type "character" which can be easily exported as one column to csv.

这篇关于将R中的数据帧输出到.csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆