How do I export a double matrix to an excel or csv

2019-08-29 13:04发布

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.

enter image description here

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

标签: r excel csv export
1条回答
ゆ 、 Hurt°
2楼-- · 2019-08-29 13:53

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.

查看更多
登录 后发表回答