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 7911387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:13:46+00:00 2026-06-03T13:13:46+00:00

I have a data.frame and I want to write it out. The dimensions of

  • 0

I have a data.frame and I want to write it out. The dimensions of my data.frame are 256 rows by 65536 columns. What are faster alternatives to write.csv?

  • 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-06-03T13:13:48+00:00Added an answer on June 3, 2026 at 1:13 pm

    If all of your columns are of the same class, convert to a matrix before writing out, provides a nearly 6x speed up. Also, you can look into using write.matrix() from package MASS, though it did not prove faster for this example. Maybe I didn’t set something up properly:

    #Fake data
    m <- matrix(runif(256*65536), nrow = 256)
    #AS a data.frame
    system.time(write.csv(as.data.frame(m), "dataframe.csv"))
    #----------
    #   user  system elapsed 
    # 319.53   13.65  333.76 
    
    #As a matrix
    system.time(write.csv(m, "matrix.csv"))
    #----------
    #   user  system elapsed 
    #  52.43    0.88   53.59 
    
    #Using write.matrix()
    require(MASS)
    system.time(write.matrix(m, "writematrix.csv"))
    #----------
    #   user  system elapsed 
    # 113.58   59.12  172.75 
    

    EDIT

    To address the concern raised below that the results above are not fair to data.frame, here are some more results and timing to show that the overall message is still “convert your data object to a matrix if possible. If not possible, deal with it. Alternatively, reconsider why you need to write out a 200MB+ file in CSV format if the timing is of the utmost importance”:

    #This is a data.frame
    m2 <- as.data.frame(matrix(runif(256*65536), nrow = 256))
    #This is still 6x slower
    system.time(write.csv(m2, "dataframe.csv"))
    #   user  system elapsed 
    # 317.85   13.95  332.44
    #This even includes the overhead in converting to as.matrix in the timing 
    system.time(write.csv(as.matrix(m2), "asmatrix.csv"))
    #   user  system elapsed 
    #  53.67    0.92   54.67 
    

    So, nothing really changes. To confirm this is reasonable, consider the relative time costs of as.data.frame():

    m3 <- as.matrix(m2)
    system.time(as.data.frame(m3))
    #   user  system elapsed 
    #   0.77    0.00    0.77 
    

    So, not really a big deal or skewing information as much as the comment below would believe. If you’re still not convinced that using write.csv() on large data.frames is a bad idea performance wise, consult the manual under the Note:

    write.table can be slow for data frames with large numbers (hundreds or more) of
    columns: this is inevitable as each column could be of a different class and so must be
    handled separately. If they are all of the same class, consider using a matrix instead.
    

    Finally, consider moving to a native RData object if you’re still losing sleep over saving things faster

    system.time(save(m2, file = "thisisfast.RData"))
    #   user  system elapsed 
    #  21.67    0.12   21.81
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame filled with factor columns, and I want to add
I have a data frame with 900,000 rows and 11 columns in R. The
I have a data frame with 900,000 rows and 11 columns in R. The
I have a data frame with several variables. What I want is create a
I have the following data: a=c(1:10) b=c(16:25) c=c(24:33) wa=c(3,7,3,3,3,3,3,3,3,1) wb=c(3,2,3,3,3,3,3,3,3,8) wc=c(4,1,4,4,4,4,4,4,4,1) z=data.frame(a,b,c,wa,wb,wc) I want
I have a data.frame with 2 columns: Node A, Node B. Each entry in
I have a data frame with two columns. First column contains categories such as
I have a data frame that looks like this, with two key columns and
I have the following dummy code: dt<-data.frame(country=letters[1:20],val=rnorm(20),siz=rnorm(20)) qplot(x=country,y=val,data=dt,geom=point,size=siz) Now I want to increase the
I have data frame with some numerical variables and some categorical factor variables. The

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.