Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6212295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:29:24+00:00 2026-05-24T06:29:24+00:00

I have a matrix that has 20 rows and 51 columns. I would like

  • 0

I have a matrix that has 20 rows and 51 columns. I would like to print this data to a plain text file. I would like the elements (which are floating point numbers) in each row to be separated by spaces, and for there to be a newline at the end of every row.

I have tried using the MASS package (write.matrix), and while it appears to the naked eye to be doing the correct thing, when I try to parse the file with a perl script, doing a simple split on white space does not generate an array of 51 elements (but rather smaller ones), so clearly the elements are not space separated.

I am super new to R, and while I have decent stats skills, I seem to suck at the data presentation side.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:29:25+00:00Added an answer on May 24, 2026 at 6:29 am

    How about write.table(mtcars, file = "mtcars.txt", sep = " ")?

    Or something like this:

    set.seed(0)
    ( m <- matrix(rnorm(100), ncol = 10) )
                  [,1]       [,2]        [,3]       [,4]       [,5]        [,6]
     [1,]  1.262954285  0.7635935 -0.22426789 -0.2357066  1.7579031  0.26613736
     [2,] -0.326233361 -0.7990092  0.37739565 -0.5428883  0.5607461 -0.37670272
     [3,]  1.329799263 -1.1476570  0.13333636 -0.4333103 -0.4527840  2.44136463
     [4,]  1.272429321 -0.2894616  0.80418951 -0.6494716 -0.8320433 -0.79533912
     [5,]  0.414641434 -0.2992151 -0.05710677  0.7267507 -1.1665705 -0.05487747
     [6,] -1.539950042 -0.4115108  0.50360797  1.1519118 -1.0655906  0.25014132
     [7,] -0.928567035  0.2522234  1.08576936  0.9921604 -1.5637821  0.61824329
     [8,] -0.294720447 -0.8919211 -0.69095384 -0.4295131  1.1565370 -0.17262350
     [9,] -0.005767173  0.4356833 -1.28459935  1.2383041  0.8320471 -2.22390027
    [10,]  2.404653389 -1.2375384  0.04672617 -0.2793463 -0.2273287 -1.26361438
                 [,7]        [,8]       [,9]       [,10]
     [1,]  0.35872890  0.01915639 -0.7970895  1.29931230
     [2,] -0.01104548  0.25733838  1.2540831 -0.87326211
     [3,] -0.94064916 -0.64901008  0.7721422  0.00837096
     [4,] -0.11582532 -0.11916876 -0.2195156 -0.88087172
     [5,] -0.81496871  0.66413570 -0.4248103  0.59625902
     [6,]  0.24226348  1.10096910 -0.4189801  0.11971764
     [7,] -1.42509839  0.14377148  0.9969869 -0.28217388
     [8,]  0.36594112 -0.11775360 -0.2757780  1.45598840
     [9,]  0.24841265 -0.91206837  1.2560188  0.22901959
    [10,]  0.06528818 -1.43758624  0.6466744  0.99654393
    

    and then:

    write.table(m, file = "m.txt", sep = " ", row.names = FALSE, col.names = FALSE)
    

    and you may want to leave row.names and col.names as TRUE (default), to keep row and column names, accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matrix in SQL reporting and I would like it to print
I would like to have a MovieClip that has a bit of depth. I
just a quick question, if I have a matrix has n rows and m
Let's say I have a matrix x which contains 10 rows and 2 columns.
I have a matrix on my report that is displaying a data set that
I have text file(test.data), which include some values and class name, for example 4.5,3.5,U1
Assume I have one matrix with two columns. Every column has thousands of values.
I have a sparsely populated matrix that's the result of a series of left
I have a class to parse a matrix that keeps the result in an
I have a program that uses JAMA and need to test is a matrix

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.