Amer
Amer

Reputation: 2251

Row binding results in R while maintaining columns labels

I have a technical question in R: how can I rowbind the following results (results1 and result2) into a data frame and keeping the columns labels for both:

result1:

meanAUC.SIM meanCmax.SIM meanTmax.SIM  AUC.OBS Cmax.OBS Tmax.OBS   PE.AUC  PE.Cmax  PE.Tmax
777.4444     74.64377     4.551254 820.7667 73.46508 3.089009 5.278274 1.604416 47.33703

result2:

 medianAUC.SIM medianCmax.SIM medianTmax.SIM AUC.OBS Cmax.OBS Tmax.OBS   PE.AUC  PE.Cmax PE.Tmax
764.6611        72.4534            4.5 795.765     68.2        3 3.908683 6.236657      50

The reason behind this is that I want to write them in a *.csv file in an organized way with the correct labeling.

Upvotes: 4

Views: 223

Answers (1)

eipi10
eipi10

Reputation: 93761

If the only reason you want to combine the data frames is to write them to a csv file, then you can instead just write each data frame separately to the same csv file. For example:

write.table(result1, "myfile.csv", row.names=FALSE, sep=",")

# If you want a blank row between them
cat("\n", file = "myfile.csv", append = TRUE)

write.table(result2, "myfile.csv", row.names=FALSE, sep=",", append=TRUE)

Here's what the file looks like:

enter image description here

Upvotes: 4

Related Questions