如何将双矩阵导出为ex​​cel或csv? [英] How do I export a double matrix to an excel or csv?

查看:230
本文介绍了如何将双矩阵导出为ex​​cel或csv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问了

解决方案

在R studio中获取数据后,您可以使用 write.csv 命令写入csv格式: / p>

  Write.csv(my_df,your_file_name.csv,row.names = T)

这将创建一个文件 your_file_name.csv >

当前工作目录中的 $ my_df 对于一个双矩阵,你可以用下面的方式形成一个新的字符矩阵,然后使用 write.csv

  my_df_new<  -  matrix(0,9,1715)
my_df_new [,2:1715]< - my_df [,2:1715]
my_df_new [,1]< - as.character(my_df [,1])$ ​​b $ b write.csv(my_df_new,your_file_name.csv,row.names = T)

请尝试这个。


I asked a question about using R to perform some web scraping for some data analysis.

Now I have the data I want. It is in a double matrix.

I am using . How do I export that double matrix to use in Excel?

EDIT:

I also have mydtm as a DocumentTermMatrix. Would that one be easier to extract?

EDIT: The code is included here : https://gist.github.com/simkimsia/7613396

解决方案

Once you have got the data in the R studio, you can simply use the write.csv command for writing into csv format:

write.csv(my_df, "your_file_name.csv", row.names=T)

This will create a file your_file_name.csv with the data of my_df in your current working directory.

EDIT:

As this won't be working for a double matrix, you could form a new character matrix in the following way and then use write.csv:

my_df_new <- matrix(0, 9, 1715)
my_df_new[,2:1715] <- my_df[,2:1715]
my_df_new[,1] <- as.character(my_df[,1])
write.csv(my_df_new, "your_file_name.csv", row.names=T)

Please try this.

这篇关于如何将双矩阵导出为ex​​cel或csv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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