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

  • Home
  • SEARCH
  • 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 6558313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:11:02+00:00 2026-05-25T13:11:02+00:00

Possible Duplicate: write.csv() a list of unequally sized data.frames I have a data frame

  • 0

Possible Duplicate:
write.csv() a list of unequally sized data.frames

I have a data frame called patients3 with 100 rows and 129 columns, which I write out to a .csv file using write.csv.

My client would like several lines appended to the beginning of this file. The exact contents of some of the lines depend on variables in the same data, and some do not. Each row has a different number of columns. The first row is simple,

FILEFORMATID 1000

I tried this code

line1 <- data.frame(cbind("FILEFORMATID", "1000"))


######### OUTPUT MANAGEMENT 4: WRITING FILES
write.csv(line1, paste("c:/personal/consults/ElwinWu/output", filenum, ".csv"))
write.csv(patients3, paste("c:/personal/consults/ElwinWu/output", filenum, ".csv"), quote = FALSE, append = T)

but got a warning

Warning message: In write.csv(patients3,
paste(“c:/personal/consults/ElwinWu/output”, : attempt to set
‘append’ ignored

and, indeed, the earlier file was overwritten.

Can this be done within R?

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-25T13:11:03+00:00Added an answer on May 25, 2026 at 1:11 pm

    There are a few ways I can think of. One would be to create a single data frame and then write it out to a CSV. This is kind of a pain. The other way(s) would be to either write out the body of the data into a file and then prepend your header info to that file or, conversely, write out the header info then append the csv body to that file.

    I’d take an approach of creating the headers first and then appending the csv second. To get the ability to append, however, you have to switch from the write.csv() to write.table()

    Here’s an example:

    header <- "my first line"
    body <- data.frame(a=rnorm(10), b=rnorm(10))
    write.table(header, file="/tmp/myfile.txt", row.names=F, col.names=F, quote=F)
    write.table(body, file="/tmp/myfile.txt", row.names=F, col.names=F, append=T, sep=",")
    

    and, as you would expect, the resulting file looks like this:

    $ cat myfile.txt 
    my first line
    1.23874432711773,-2.2589990017634
    0.231896206292307,1.17882048865978
    -0.314437880898758,0.902090923407546
    1.4997037042092,0.626724662264575
    0.0695743692981956,0.250950969342156
    1.33403372000003,0.552648907461989
    0.182234972030415,0.950754253582309
    -0.0960762881273546,-0.714485753494804
    -0.850532439053779,1.89170555264949
    0.269472111643762,1.39531731667127
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Do write-only properties have practical applications? A getter without a setter makes
Possible Duplicate: Searching through list I need to write a function 'once' which, given
Possible Duplicate: How to write conditional comment for non IE browsers? i have a
Possible Duplicate: Invalid read/write sometimes creates segmentation fault and sometimes does not I have
Possible Duplicate: Oracle DB: How can I write query ignoring case? I have an
Possible Duplicate: Why use document.write? Considering the negative effects of document.write(), why are most
Possible Duplicate: byte[] array pattern search I am trying to write a simple compression
Possible Duplicate: C++ HTML template framework, templatizing library, HTML generator library Planning to write
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
I have some CSV data files that I want to import into mySQL. I

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.