Add 3 numbers to the top of a dataframe


I have kind of an odd request to manipulate a dataframe. I'm tweaking a list input files for a box model within R. I'm creating a list of files from my directory, dividing all the values (except time) by 60.

files<-list.files(pattern = "^MOZART(.*)conc", full.names = FALSE)

Mozart<-lapply(files, FUN = function(x){
  read.table(x, header = TRUE, sep = "")})

NewList<-map(Mozart, function(x){
    mutate(across(everything(), ~./60))%>%
    mutate(time = time*60)

Code there is simple enough. However, I need the dataframe that I end up writing to have format like this:

time H2O CO2 CH2O
0 10 11 222

Basically I need to add those three numbers to the top of each dataframe. They aren't supposed to be rows or columns, just numbers. Is there any way of doing this. Any help is greatly appreciated.

a data.frame is rows and columns in a rectangular arrangement
its possible to arrange data heirarchicly in lists (i.e. non rectangularly) but they aren't dataframes.
What you are asking for is therefore impossible.
However, if you just mean that you want to write out your dataframes to files, and have 3 numbers as the first 3 lines of those files, with the tab seperated rectangular dataframe underneath, thats perfectly possible (and not even difficult to do)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

The second option is percisely what I mean. The box model I'm using doesn't paticularly care about the file, as long as it has that format. I'm just never tried to do something like this in R, and was struggling to find answers on google and in R documentation.

outfile <- file("examplefile.txt","w+")
writeLines("45\n0\n2",con = outfile)
write.table(x = mtcars,
          file = outfile,
          append = TRUE,
          sep = "\t",
          row.names = TRUE,
          col.names = TRUE)