Kim Stacks
Kim Stacks

Reputation: 10832

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

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

Upvotes: 0

Views: 2919

Answers (1)

StrikeR
StrikeR

Reputation: 1628

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.

Upvotes: 2

Related Questions