I have a R object say:
mat <- matrix(1:100,nrow=20)
I want to send this matrix to .txt file so that the exported .txt file contains 20 rows and 5 columns. Is there easy way to do this?
Thanks in advance,
To create an R Markdown report, open a plain text file and save it with the extension . Rmd. You can open a plain text file in your scripts editor by clicking File > New File > Text File in the RStudio toolbar. Be sure to save the file with the extension .
No packages required:
write.table(mat, file="mymatrix.txt", row.names=FALSE, col.names=FALSE)
This will use space as a separator, but you can also add sep = ...
if you prefer tabs or any other delimiters (replace ...
with your desired delimiter, of course).
The documentation is a great resource. :)
library(MASS)
mat <- matrix(1:100,nrow=20)
write.matrix(mat,'/path/to/file.txt',sep = "\t")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With